ishkabible, on 22 May 2012 - 02:56 PM, said:

the '&' operator is the bit-wise 'and' operator. because 1 is represented by the first bit and all other bits are multiples of 2 all other bits don't effect weather a number is odd or not. by 'anding' the first bit with 1 you check to see if the first bit is set. if it then the number is odd. but we want weather it is even or not; this means inverting the result with '!'.

Not exactly. Your actually anding all of the corresponding bits.

For example,

1 0 1 0 0 1 1 0 & 1 0 1 0 1 1 1 1 ------------ = 1 0 1 0 0 1 1 0

In C/C++ 0 is false, and not zero is true. true and true == true, true and false == false, false and false == false.

Because 1 only has one on bit,

0 0 0 0 0 0 0 1

Anything anded with 1 is either 1 or zero.

0 0 0 0 0 0 0 1 & ? ? ? ? ? ? ? ? = ------------- 0 0 0 0 0 0 0 ?