Bitwise operators work directly on the binary (bit-level) representation of integers. Python supports six bitwise operators: AND (&), OR (|), XOR (^), NOT (~), left shift (<<), and right shift (>>). These operators manipulate individual bits, making them useful for low-level programming, flags, permissions, and performance-critical code.
Key Points
& (AND) sets a bit to 1 only if both bits are 1: 5 & 3 → 1.
| (OR) sets a bit to 1 if either bit is 1: 5 | 3 → 7.
^ (XOR) sets a bit to 1 if the bits are different: 5 ^ 3 → 6.
~ (NOT) flips all bits (bitwise complement): ~5 → -6.