# C 按位运算符C Bitwise Operators

## 语法Syntax

AND-expressionAND-expression:
equality-expression  equality-expression
AND-expression & equality-expression  AND-expression & equality-expression

exclusive-OR-expressionexclusive-OR-expression:
AND-expression  AND-expression
exclusive-OR-expression ^ AND-expression  exclusive-OR-expression ^ AND-expression

inclusive-OR-expression:inclusive-OR-expression:
exclusive-OR-expression  exclusive-OR-expression
inclusive-OR-expression | exclusive-OR-expression  inclusive-OR-expression | exclusive-OR-expression

C 按位运算符如下所述：The C bitwise operators are described below:

& 按位“与”运算符将其第一操作数的每个位与其第二操作数的相应位进行比较。The bitwise-AND operator compares each bit of its first operand to the corresponding bit of its second operand. 如果两个位均为 1，则对应的结果位将设置为 1。If both bits are 1, the corresponding result bit is set to 1. 否则，将对应的结果位设置为 0。Otherwise, the corresponding result bit is set to 0.
^ 按位“异或”运算符将其第一操作数的每个位与其第二操作数的相应位进行比较。The bitwise-exclusive-OR operator compares each bit of its first operand to the corresponding bit of its second operand. 如果一个位是 0，另一个位是 1，则相应的结果位将设置为 1。If one bit is 0 and the other bit is 1, the corresponding result bit is set to 1. 否则，将对应的结果位设置为 0。Otherwise, the corresponding result bit is set to 0.
|| 按位“与或”运算符将其第一操作数的每个位与第二操作数的相应位进行比较。The bitwise-inclusive-OR operator compares each bit of its first operand to the corresponding bit of its second operand. 如果其中一个位是 1，则将对应的结果位设置为 1。If either bit is 1, the corresponding result bit is set to 1. 否则，将对应的结果位设置为 0。Otherwise, the corresponding result bit is set to 0.

## 示例Examples

``````short i = 0xAB00;
short j = 0xABCD;
short n;

n = i & j;
``````

``````n = i | j;

n = i ^ j;
``````

Microsoft 专用Microsoft Specific

``````  11111111 11110000
& 00000000 01100011
_________________
00000000 01100000
``````