question about binary and serial info

Jordan Rastrick jrastrick at student.usyd.edu.au
Thu Aug 18 00:00:14 EDT 2005


Sounds like you want the bitwise and operator, &

>>> 2 & 3
2
>>> 32 & 16
0
>>> 31 & 12
12

etc.

neph... at xit.net inquired:
> i have an interesting project at work going on. here is the challenge.
> i am using the serial module to read data from a serial input.
> it comes in as a hex. i need to make it a binary and compare it bit by
> bit to another byte. They have some weird way they set this up that i
> have to compare these things with AND. in other words, if bit 1 is 1
> AND bit 1 is 1 then the real value is 1...
>
> long story short. is there a good way to compare bytes, bit by bit with
> one of the modules of python. i want to know so i dont get halfway into
> developing this and find that there is a much better way to do this
> than by hand.
> 
> thanks for any suggestions.
> sk <><




More information about the Python-list mailing list