Possible Duplicate:
Packing 4 Integers as ONE BYTE?
I have four integers {a, b, c, d} that can have the following range of values:
a – {0 or 1} (1 bit)
b – {0 or 1} (1 bit)
c – {0, 1, 2, …, 7} (3 bits)
d – {0, 1, 2, …, 7} (3 bits)
Is it possible to ‘convert’ them to ONE INTEGER (between 0 – 255) without having to do bit packing/unpacking? if so, how do I achieve this in Python?
Equivalently to my previous answer, but using
*and+instead of<<and|, you can dofor packing and
for unpacking. This does the same as the bit operations, just without using bit operations. I don’t see the point, but you asked for it.