I just started learning about bit wise operation and want to ask why and 1 ( &1) bitwise operation always return 0 or 1 .
Why and 1 ( &1) bitwise operation always return 0 or 1
12.3k Views Asked by hung.dev At
4
There are 4 best solutions below
0

When you perform a & 1
it will always return 0 or 1 depending upon the the last binary digit of a.
Rules:
0 & 0 = 0
0 & 1 = 0
1 & 1 = 1
For example:
a = 5 //5 = 0101
b = a & 1 = 1 //(0101 & 0001)
a = 6 //6 = 0110
b = a & 1 = 0 //(0110 & 0001)
therefore any number & 1 will always be either 0 or 1
in binary ... any number
or
where x can be 0 or 1
1 in binary is
so