To generate all subsets of n elements, loop through all integers from 0 to 2n−1. For each integer mask, check which bits are set to determine which elements are in that subset.
For n=3 elements {0,1,2}, loop through masks 0 to 7: 000,001,010,011,100,101,110,111. Each mask corresponds to one subset.
To extract which elements are in subset represented by mask m, loop through bits i from 0 to n−1 and check if bit i is set: (m&(1<<i))=0.