Getting at the bits of a 32-bit integer

Jacob H jacobsmail at postmark.net
Mon Aug 23 19:52:07 EDT 2004


Hi there list,

I'm a beginning programmer, so please correct me if any of the
following assumptions are wrong.

Suppose I have the decimal number 255. Since integers in Python are 32
bits, it would look like this in binary:

00000000 00000000 00000000 11111111

There are plenty of unused bits to the left of the number itself. If I
wanted to use some of these bits as true/false flags, how would I go
about it? In Python, how do I write code that gets at the leftmost
byte, or the third bit from the left of the set of 32, or the
rightmost byte plus the bit to its left, etc...

Thanks in advance for any help on this. :)

Jacob



More information about the Python-list mailing list