Binary operators, often forget, so hang on the blog for easy reference later.
Note: The binary of 1 is 00 ... 00001, 0 of the binary is 000 ..... 0000.3 of the binary is 00 ... 00011, 5 of the binary is 00 .... 00101
1. Bitwise AND operator (&)
Rule: 0&0 = 0, 0&1 = 0, 1&1=1. That is, two bits are 1 at the same time, the result is 1, otherwise 0
Example: 3 & 5 = 1. (000011 & 000101 = 000001)
2. Bitwise OR operator (|)
Rule: 0|0 = 0,1|0 = 1,0|1 = 1,1|1 = 1 The two bits of the participating bit operation as long as there is a 1, then 1
Example: 3 | 5 = 7 (0000011 | 00000101 = 0000111)
3. Xor operator (^ also called XOR (Will encounter XOR, which is XOR))
Rule: 0^0 = 0,0^1=1,1^0=1,1^1=0 The two bits of the bit operation as long as the same is 0, the difference is 1
Example: 3^5 = 6 (00000011^00000101=00000110)
The special arbitrary number ^ 0 = any number.
4. Take the inverse operator (~)
Rule: bits 0 becomes 1, 1 becomes 0
5. Shift Left (<<)
Rule: the equivalent of multiplying by 2
6. Move right (>>)
Rule: equivalent to dividing by 2
Correlation operations of binary operators