Bitmasks as Tiny Sets
Represent subsets as integers.
An Integer as a Set
A single integer can stand in for a whole set: bit i being 1 means element i is in. This packs subsets into one tiny, fast value. 🎒
The Empty and Full Sets
The number 0 is the empty set, while a value with the lowest n bits all on means every element is present.
empty = 0
full = (1 << 4) - 1 # 0b1111, four elementsAll lessons in this course
- AND, OR, XOR & Shifts
- Set, Clear & Toggle a Bit
- Count Bits and Lowest Set Bit
- Bitmasks as Tiny Sets