17.4.8 Bitwise operators
Bitwise operators perform bitwise AND (&) and OR (|) operations.
- Organization of this subsection
(1) Format
- Bitwise AND
expression & expression
- Bitwise OR
expression | expression
(2) Description
Either or both of the operands for a bitwise operator must be the integer type. Bitwise operators perform normal arithmetic conversion according to the data type.
The following explains the bitwise operators.
Operator |
Description |
---|---|
& |
The bitwise AND operator compares a bit of the first operand with the corresponding bit of the second operand. If both the bits are 1, the resulting bit is set at 1. If not, the resulting bit is set at 0. |
| |
The bitwise OR operator compares a bit of the first operand with the corresponding bit of the second operand. If one of both the bits is 1, the resulting bit is set at 1. If not, the resulting bit is set at 0. |
-
The bitwise AND operator compares two expressions bit by bit, and sets the resulting bit as follows:
Bits of expression 1
Bits of expression 2
Result
0
0
0
0
1
0
1
0
0
1
1
1
-
The bitwise OR operator compares two expressions bit by bit, and sets the resulting bit as follows:
Bits of expression 1
Bits of expression 2
Result
0
0
0
0
1
1
1
0
1
1
1
1