I have 4 bytes of binary data (big-endian) that I want to unpack. If it contained two two-byte unsigned values, it would be simple:
a, b = data.unpack("C>C>")
But what if the data contains a 3-byte value ( a
) followed by a 1-byte value ( b
)? The decompression method does not seem to be able to handle formats other than 8-, 16-, 32- and 64-bit integers. Here is what I came up with:
a, b = data.unpack("L>XC")
a >>= 8
(If the data were of little value, a &= 0xFFFFFF
it could be used to delete the last (highest) byte.)
Is there a more elegant way to unzip these values?