Bit 6 kinds of arithmetic operation
&: Bitwise AND and
|: Bitwise or OR
^: XOR Bitwise xor
~: Bitwise not
<<: Left
>>: right
1. Bitwise AND &
Principle: The results are 1 to 1, 0 otherwise
Uses: The byte certain one of these bits is set to 0. Without affecting the operation of other bits
0xFFFF operation and does not change the original data
Eg: 16 bits to the highest position and the operation 0x0FFF 0
2. Bitwise OR |
Principle: all output 0 is 0, 1 or output
Uses: The byte certain one of these bits is set to 1. Without affecting the operation of other bits
And 0x0000 or not to change the operation data
Eg: 16 bit operation and the highest position of 0xF000 1
3. XOR ^
Principle: different output 1, the same output 0
Uses: 1. A particular bit inversion
2. Swap two variable values
With XOR operation does not change the original data 0xFFFF
4. ~ Negate operation
Principle: 1 to a 0, 0 to 1
Uses: positive number, source code, complement, anti-code consistent
Negative = complement source symbols does not move, inverted +1
Inverted a number a = - (a + 1)
5. Left and right:
Uses: for rapid multiplication and division of integers
Left: shift of n bits by n-th power of 2
Right: shift of n bits in addition to n-th power of 2