@@bit operations

Definition: Convert an integer to binary and perform operations based on binary bits.
Operation symbols:

& 按位与
| 按位或
^ 按位异或
<<左移
>>右移
14 --> 01110
19 --> 10011
14 & 19 = 00010 = 2 -00
14 | 19 = 111111 = 31 -11
14 ^ 19 = 11101 = 29 相同为0不同为1
14 << 2 = 111000 = 56 向左移动低位补0
14 >> 2 =11 =3 向左移动去掉低位
| 按位或用来增加属性
& 按位与用来判定属性

Guess you like

Origin blog.csdn.net/qq_42307546/article/details/132891136