Bitwise operators perform bitwise AND (&) and OR (|) operations.
expression & expression
expression | expression
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. |
Bits of expression 1 | Bits of expression 2 | Result |
---|---|---|
0 | 0 | 0 |
0 | 1 | 0 |
1 | 0 | 0 |
1 | 1 | 1 |
Bits of expression 1 | Bits of expression 2 | Result |
---|---|---|
0 | 0 | 0 |
0 | 1 | 1 |
1 | 0 | 1 |
1 | 1 | 1 |