Python 位运算符
Python 位运算符
位运算符用于比较(二进制)数字:
| 运算符 | 名称 | 描述 |
|---|---|---|
| & | AND | 如果两个位都是 1,则将每个位设置为 1 |
| | | OR | 如果两个位中有一个为 1,则将每个位设置为 1 |
| ^ | XOR | 如果两个位中只有一个为 1,则将每个位设置为 1 |
| ~ | NOT | 反转所有位 |
| << | Zero fill left shift | Shift left by pushing zeros in from the right and let the leftmost bits fall off |
| >> | Signed right shift | Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off |

