& performs bitwise AND . That is, it performs an AND operation for all input bits.
In binary format:
2 = 0000000010 222 = 1011011110 2 & 222 = 0000000010 ( = 2)
Do not confuse & with && . & makes a bitwise AND , and && makes logical AND .
2 && 222 = true 2 & 222 = 2
As for 1 & 11
1 = 0001 11 = 1011 1 & 11 = 0001 ( = 1)
So 1 & 11 = 1
Further reading:
http://en.wikipedia.org/wiki/Binary_and#AND
http://en.wikipedia.org/wiki/AND_gate
source share