I am trying to write 4 integers to a single byte.
In the example below is I can unpack \x11 and then read the bits (answer = 1 2 0 0) but how would I do the reverse? i.e. how would I pack 1 2 0 0 into \xll
import struct
val = struct.unpack('B', '\x11')[0]
a = val & 7
b = (val >> 3) & 7
c = (val >> 6) & 1
d = (val >> 7)
print a, b, c, d
I am pretty new to all this… many thanks!
Like this: