Bit manipulation
AlgorithmsOperate on binary directly with AND/OR/XOR/shifts — XOR cancels, masks encode small sets.
Definition
Bit manipulation works on a number's binary representation with AND, OR, XOR, NOT, and shifts. The recurring tricks: x & (x - 1) clears the lowest set bit, XOR cancels equal values (so it finds a lone unpaired number), and a bitmask packs a set of up to ~32 booleans into one integer.
When to use
Reach for bit tricks on single-number / XOR problems, subset enumeration via bitmasks, and space-tight flag sets. In JavaScript, bitwise operators coerce operands to 32-bit signed integers — a gotcha for values beyond 2³¹.