how to get bit info

Tim Lesher tlesher at gmail.com
Thu Jun 17 16:06:31 EDT 2010


On Jun 17, 3:51 pm, Back9 <backgoo... at gmail.com> wrote:
> Hi,
>
> I have one byte data and want to know each bit info,
> I mean how I can know each bit is set or not?

You want the bitwise-and operator, &.

For example, to check the least significant bit, bitwise-and with 1:

>>> 3 & 1
1
>>> 2 & 1
0



More information about the Python-list mailing list