按位运算符


按位运算符

位运算符用于(二进制)数字:

Operator Name Description Example 尝试一下
AND Sets each bit to 1 if both bits are 1 x & y 尝试一下 »
| OR Sets each bit to 1 if one of two bits is 1 x | y 尝试一下 »
 ^ XOR Sets each bit to 1 if only one of two bits is 1 x ^ b 尝试一下 »
<< Zero fill left shift Shift left by pushing zeros in from the right x << 2 尝试一下 »
>> Signed right shift Shift right by pushing copies of the leftmost bit in from the left, and let the rightmost bits fall off x >> 2 尝试一下 »