how to get bit info

Anssi Saari as at sci.fi
Sat Jun 19 05:11:40 EDT 2010


Back9 <backgoodoo at gmail.com> writes:

> 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?

Other than the tedious anding, oring and shifting, you can convert
your byte to a string (with function bin) and use normal string
handling functions to check if individual bits are 0 or 1. 

String format is also handy if you happen to need to do things like
reversing the bit order or slicing and joining together various bits
from different bytes.

I seem to invariably need to do some bit order reversing when I mess
around with serial data, which is one reason why I like Python.



More information about the Python-list mailing list