& Bitwise AND if two corresponding bits are 1, then the result value of this bit is 1, otherwise 0
int fun (int n) { return (n&1); Returns 1 for odd, 0 for even. }
According to the arithmetic rules of bitwise AND, if two corresponding bits are 1, then the result value is 1, otherwise 0. The key to N&1 is the last bits, which determines whether n is an odd or even number. That is, N and 1 bitwise operations regardless of how many bits of N, as long as the last one is 1, the last one is 1 means that n must be an odd number (2k+...+1 must be odd), at this time with 1 bitwise AND operation return value is 1, otherwise the return value is 0, that is, n is even. Bit operations are faster than% operations and learn to use bits and arithmetic to judge parity.
In short remember: n&1 return value is 1 means n is odd, the return value is 0 means n is even.
A discussion of parity between C + + and arithmetic