Bitwise Operators

Definition

The bitwise operators perform bitwise AND, bitwise inclusive OR, left shift, right shift, and one’s complement (unary).

Bitwise AND & Masks off the specified bits
Bitwise inclusive OR | Turns on the specified bits
Bitwise exclusive OR ^ Sets to 1 each bit position where the operands have different bits, and sets to 0 each bit position where the operands have the same bits.
Bitwise 1’s complement ~ Changes each 1-bit into a 0-bit and vice-versa.
Left Shift << Shifts to the left the left operand by the number of bit positions indicated by the right operand.
Right Shift >> Shifts to the right the left operand by the number of bit positions indicated by the right operand.

Operand Type

These operators apply to integers.

Result Type

The following table shows each of the possible results for bitwise AND, OR, and exclusive OR (XOR).

0 1
AND (&)

0

1

0

0

0

1

OR ( | )

0

1

0

1

1

1

XOR ( ^ )

0

1

0

1

1

0