The standard structural module does not support all possible sizes, so you need to either combine several bits (see Dietrich's answer), or you can use external modules such as bitstring .
>>> from bitstring import BitArray >>> b = BitArray(bytes=b'\x05\x00\x00\x00\x00\x00\x05\x00') >>> b.unpack('<H6B') [5, 0, 0, 0, 0, 5, 0]
which is consistent with the standard struct.unpack . But now we can instead unpack the second element as a 6-byte (48-bit) unsigned unsigned integer:
>>> b.unpack('<H, uintle:48') [5, 21474836480]
which gives you the same result as Dietrichβs answer, and also shows that you have something wrong with your question! What do you need in this case:
>>> b.unpack('uintle:48, <H') [5, 5]
Note that you could also write <H as uintle:16 if you need a more consistent write.
source share