Using any bit operation how can a binary number be checked whether it is even or odd?

Questions by indraneely

Showing Answers 1 - 2 of 2 Answers

maddynator

  • Dec 23rd, 2010
 

Take one's compliment of the number and then mod by 2.

num = ~num;
if (num%2 == 0) {
num is odd;
else 
num is even;

if you can ONLY use one bit operation, then AND with 0000 0001 is also good.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions