I have four integers {a, b, c, d} that can have the following range of values:
a - {0 or 1} (1 bi
If you need to this kind of thing a lot then bit shifting can become tedious and error prone. There are third-party libraries that can help - I wrote one called bitstring:
To pack and convert to a byte:
x = bitstring.pack('2*uint:1, 2*uint:3', a, b, c, d).bytes
and to unpack:
a, b, c, d = bitstring.BitArray(bytes=x).unpack('2*uint:1, 2*uint:3')
This is probably overkill for your example, but it's helpful when things get more complicated.