To generate all subsets of elements, loop through all integers from to . For each integer , check which bits are set to determine which elements are in that subset.
For elements , loop through masks to : . Each mask corresponds to one subset.
To extract which elements are in subset represented by mask , loop through bits from to and check if bit is set: .