Iterate all subsets of a mask:
sub = mask
while sub > 0:
// process subset 'sub'
sub = (sub - 1) & mask
// don't forget empty subset
Why it works: Decrementing flips trailing s and sets next to . The & mask keeps only bits from the original mask.
Example: mask , subsets: .
Time: for iterating all subsets of all masks from to .