Help with C bitwise code

Thread Solved

Join Date: Sep 2005
Posts: 12
Reputation: desertstorm is an unknown quantity at this point 
Solved Threads: 0
desertstorm desertstorm is offline Offline
Newbie Poster

Help with C bitwise code

 
0
  #1
Sep 30th, 2005
Could someone help me with this. I need to know how to write this in code for C.

"if hashValue(variable) has a non-zero bit in the 4 leftmost (highest) bits"

It has to do with bitwise shifting and is basically just an if statement's condition. Thanks
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 5
Reputation: shric will become famous soon enough shric will become famous soon enough 
Solved Threads: 1
shric's Avatar
shric shric is offline Offline
Newbie Poster

Re: Help with C bitwise code

 
0
  #2
Sep 30th, 2005
This has the pungeant stench of homework, so I won't just do it for you.

Have you googled at all for C bit manipulation, or bitwise operations?

Hint: You will need to mask away the bits that you are not concerned about (the lower bits), so what mask would you use, and what bitwise operator?
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 12
Reputation: desertstorm is an unknown quantity at this point 
Solved Threads: 0
desertstorm desertstorm is offline Offline
Newbie Poster

Re: Help with C bitwise code

 
0
  #3
Sep 30th, 2005
I understand how to bit shift and all that, but the thing I don't understand is how you would check just the 4 leftmost bits to see if they are a non-zero bit. I have interpreted non-zero to mean 1, as in 0 or 1 in bits. I'm not sure if this is what it means but that's they way I have interpreted it. Also one way I thought about doing this was:

Since 8 bits equals 1 byte, I bit shifted the hashNumber 4 spaces to the right and that would set the four left spots to zero, then I compared them using | to "00000000", and checked to see if the output was still "00000000" and if it was, then that means the 4 leftmost bits must have all been zero's. Does this sound correct to you? Thanks for the assistance.
Reply With Quote Quick reply to this message  
Join Date: Sep 2005
Posts: 12
Reputation: desertstorm is an unknown quantity at this point 
Solved Threads: 0
desertstorm desertstorm is offline Offline
Newbie Poster

Re: Help with C bitwise code

 
0
  #4
Sep 30th, 2005
Nevermind my previous post, that makes no sense. I just received help on this from another person and learned that I'm way off. Thanks for your help. Greatly appreciated.
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