The following data is added to a bitstream
bitstream.add(BYTE_OFFSET_SIZE_FLAG, 1) # value = 0
bitstream.add(NON_OVERLAPPING_AU_RANGE_FLAG, 1) # value = 0
bitstream.add(POS_40_BITS_FLAG, 1) # value = 0
bitstream.add(BLOCK_HEADER_FLAG, 1) # value = 1
bitstream.add(MIT_FLAG, 1) # value = 1
bitstream.add(CC_MODE_FLAG, 1) # # value = 1
bitstream.add(0, 2) # to make the bitstream of 8 bits
When I unpack it:
data = struct.unpack('>B', in_file.read(1))[0] # evaluates to 28, in bin 00011100
ds_header["byte_offset_size_flag"] = data >> 7 # value = 0
ds_header["non_overlapping_au_range_flag"] = data >> 6 & 0x01 # value = 0
ds_header["pos_40_bits_flag"] = data >> 5 & 0x001 # value = 0
ds_header["block_header_flag"] = data >> 4 & 0x0001 # value = 1
ds_header["mit_flag"] = data >> 3 & 0x00001 # value = 1
ds_header["cc_mode_flag"] = data >> 2 & 0x000001 # value = 1
ignore = data & 0x00000011 # value = 16, but 0 is expected
I do not really understand why the ignore value is 16, since the last 2 bits of data are 00..
What am I doing wrong?
0x00000011is 17 and28 & 17 = 16is correct. I suspect that you wantbeverywhere that you havexin the above code (although as @Marat points out, you got lucky in the other places).0x00000011is in base 16, not base 2. Hex isn't binary (though they are naturally related). The meaning of0x00000011is 1x16 + 1 = 17, not1x2 +1 = 3