In C ++ bitwise exclusive OR ^, &, |

&: Only 2 are both 1, then the result is 1, otherwise 0; for example: 1 = 1 & 1,1 & 0,0 & 0 = 0 = 0 = 1 & 0,0;

11 & 3 = 3

   00001011
&  00000011 = 00000011 = 3

|: As long as there is a 1, then the result is 1, otherwise 0; for example: 1 & 1, 1 & 1 = 0 = 0 = 1,0 & 0,0 & 1 = 1;

11 | 3 = 11

   00001011
|  00000011 = 00001011 = 11

>>: displacement to the right, that is, the mantissa bits removed, for example: 153 >> 2,153 binary is: 10011001, remove the rear end 100110,100110 2 is converted into decimal 10011001,38 = 100110 = 38,153, "01" is removed.

<<: left shift, is to rid the beginning of double-digit, 00-digit mantissa plus, for example:

107 = 0110 1011 <<2 << 172 = 1010 1100

Since in the computer are 32-bit

107 = 0000 0000 0000 0000 0000 0000 0110 1011 <<2 << 428 = 0000 0000 0000 0000 0000 0001 1010 1100

^: Two identical number becomes 0, whereas 1 is, for example: 1 = 1 & 0,1 & 1,0 & 0 = 0 = 0, 0 & 1 = 1;

11^3 = 8

   00001011
^  00000011 = 00001000 = 8

Any number of XOR  ^ 0 the same value obtained:

a^0 = a

Any number of different or the same number of the same value twice obtained:

a^b^b = a

Guess you like

Origin www.cnblogs.com/gkh-whu/p/11478300.html