need help comparing bits

Thread Solved
Reply

Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

need help comparing bits

 
0
  #1
Aug 18th, 2005
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 <><
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,856
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 866
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: need help comparing bits

 
0
  #2
Aug 18th, 2005
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++
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: need help comparing bits

 
0
  #3
Aug 18th, 2005
i found it.
the & operator.
thanks
Reply With Quote Quick reply to this message  
Join Date: Oct 2004
Posts: 3,856
Reputation: vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice vegaseat is just really nice 
Solved Threads: 866
Moderator
vegaseat's Avatar
vegaseat vegaseat is online now Online
DaniWeb's Hypocrite

Re: need help comparing bits

 
0
  #4
Aug 19th, 2005
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
May 'the Google' be with you!
Reply With Quote Quick reply to this message  
Join Date: Jun 2005
Posts: 39
Reputation: nephish is an unknown quantity at this point 
Solved Threads: 0
nephish nephish is offline Offline
Light Poster

Re: need help comparing bits

 
0
  #5
Aug 21st, 2005
cool thanks, very helpful, i have been re-arranging stuff now.
all is starting to look better.
regards
sk
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC