&
is bitwise AND
(only 1 & 1 => 1
):
LiveDemo
CREATE TABLE #tFlags(Flags INT);
INSERT INTO #tFlags VALUES (524675), (525698);
select *
,[bitwise AND] = CONCAT(Flags, '& 1 = ')
,[result] = Flags & 1
from #tFlags;
How it works:
000010000000000110000011 524675
000000000000000000000001 1 &
------------------------
000000000000000000000001 1
and:
000010000000010110000010 525698
000000000000000000000001 1 &
------------------------
000000000000000000000000 0
The simple answer is:
- odd number & 1 = 1
- even number & 1 = 0
EDIT:
Number & 255: You can get rid of data except byte one.
00000001 00101100 300
00000000 11111111 255 &
-----------------
00000000 00101100 44
The point is you can treat binary number and bitwise operation as masking and use it to set/reset/xor value based on specific position.