Bitmasking
Learn Bitmasking (Bit Manipulation, Data Structures & Algorithms) with worked examples, diagrams and interview questions. Free on JavaSchoolLab.
Representing a Set of Choices as a Single Integer A BITMASK uses each bit of an integer to represent whether one item is INCLUDED (1) or EXCLUDED (0) from a set. For n items, an integer from 0 to 2ⁿ - 1 can represent EVERY possible subset - enumerating all 2ⁿ masks enumerates all subsets.