The AND (&
), OR (|
), and XOR (^
) operators generate new values with the bit pattern composed from its two operands:
For each bit position in the result of the bitwise AND operator (the &
operator) the bit is 1 if both operands contain 1; otherwise, the result is 0. For the OR (inclusive or) operator (the |
operator), the bit is 1 if either or both operands contain 1; otherwise, the result is 0. For the XOR (exclusive or) operator (the ^
operator), the bit is 1 if either but not both operands contain 1; otherwise, the result is 0.