Monday, June 21, 2010

bitwise operator

27&14
0001 1011
0000 1110
---------
0000 1010
only 1 & 1 is 1, any other is 0
in decimal, it's 10; in Hex, it's A

27|14
0001 1011
0000 1110
---------
0001 1111
only 0 | 0 is 0, any other is 1
in decimal, it's 31; in Hex, it's 1F

27^14
0001 1011
0000 1110
---------
0001 0101
if same 0, if different 1
in decimal, it's 21; in Hex, it's 15

so, if z = x^y; z^x = y; z^y = x;

No comments:

Post a Comment