DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   Python (http://www.daniweb.com/forums/forum114.html)
-   -   need help comparing bits (http://www.daniweb.com/forums/thread30757.html)

nephish Aug 18th, 2005 1:28 am
need help comparing bits
 
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 <><

vegaseat Aug 18th, 2005 3:20 pm
Re: need help comparing bits
 
I used to do that sort of thing in C, and I know the operator module has most of the C like syntax in it. You will have to learn to be a "shifty" person. With all those >> and << your code looks like C++

nephish Aug 18th, 2005 3:36 pm
Re: need help comparing bits
 
i found it.
the & operator.
thanks

vegaseat Aug 19th, 2005 12:12 pm
Re: need help comparing bits
 
Great, I managed to put a code snippet together from my C experience. Take a look at it:
http://www.daniweb.com/code/snippet360.html

nephish Aug 21st, 2005 11:06 pm
Re: need help comparing bits
 
cool thanks, very helpful, i have been re-arranging stuff now.
all is starting to look better.
regards
sk


All times are GMT -4. The time now is 11:42 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC