Bitwise Operators

AND, OR, XOR, NOT, shifts.

AND (&): Both bits must be 11. 1010 & 1100 = 1000

OR (|): At least one bit is 11. 1010 | 1100 = 1110

XOR (^): Exactly one bit is 11. 1010 ^ 1100 = 0110

NOT (~): Flip all bits. ~1010 = ...0101 (depends on integer size)

Left shift (<<): Multiply by 22. 5 << 1 = 10 (101210102101_2 \to 1010_2)

Right shift (>>): Divide by 22. 5 >> 1 = 2 (1012102101_2 \to 10_2)

These are O(1)O(1) operations, much faster than arithmetic on large numbers.