How to select odd and even for the input

thatoneguy

Joined Feb 19, 2009
6,359
Test the least significant bit. If it is a 0, number is even, if it is a 1, number is odd.

eg:
210 = 102 (LSB=0, number is even)

The only special case is zero, which is both odd and even.

A more complicated test is to divide number by 2, and check the remainder (mod2). If there is a remainder, number is odd, if not, it is even. The test for zero needs to come before this though.
 
Top