how to get bit info

Irmen de Jong irmen.NOSPAM at xs4all.nl
Thu Jun 17 16:10:32 EDT 2010


On 17-6-2010 21:51, Back9 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?
>
> TIA

Use bitwise and, for instance, to see if the third bit is set:

byte = 0b11111111
if byte & 0b00000100:
	print "bit is set"

-irmen



More information about the Python-list mailing list