0 day streak
2. Algorithms and patternsBit manipulation

Bit manipulation

Bit manipulation means working directly with the individual 1s and 0s inside an integer. A 32-bit number is really 32 on/off switches, and operations like AND, OR, XOR and shifting act on all of them at once in a single CPU instruction. That lets you pack a set of small flags into one number, test or flip a specific bit, or check whether a number is a power of two with one expression. XOR has a handy property: anything XORed with itself cancels to zero, which can find the one unpaired item in a list. You meet it in permission flags, compression, hashing, graphics and low-level systems code, and in plenty of interview puzzles.

In this lesson: A playground with 32 toggleable bits and live AND, OR, XOR and shift results.