943,997 Members | Top Members by Rank

Ad:
  • Python Discussion Thread
  • Marked Solved
  • Views: 3086
  • Python RSS
Aug 18th, 2005
0

need help comparing bits

Expand Post »
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 <><
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
nephish is offline Offline
39 posts
since Jun 2005
Aug 18th, 2005
0

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++
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Aug 18th, 2005
0

Re: need help comparing bits

i found it.
the & operator.
thanks
Reputation Points: 10
Solved Threads: 0
Light Poster
nephish is offline Offline
39 posts
since Jun 2005
Aug 19th, 2005
0

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
Moderator
Reputation Points: 1333
Solved Threads: 1403
DaniWeb's Hypocrite
vegaseat is offline Offline
5,792 posts
since Oct 2004
Aug 21st, 2005
0

Re: need help comparing bits

cool thanks, very helpful, i have been re-arranging stuff now.
all is starting to look better.
regards
sk
Reputation Points: 10
Solved Threads: 0
Light Poster
nephish is offline Offline
39 posts
since Jun 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Python Forum Timeline: Parsing xml file
Next Thread in Python Forum Timeline: How to use 'top' using Python





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC