A submask of a bit mask has no set bits outside . Start with and repeatedly replace a positive byProcess each positive before this update and stop when it becomes zero. To include the empty submask, process zero once and stop before updating it; otherwise the update can return to .
Subtracting one clears the lowest set bit and sets the lower positions. The bitwise AND with removes forbidden positions, producing the largest permitted submask strictly below the previous one. This proves decreasing order, no duplicates and no skipped submask.
For , the order is . A bit mask with set bits has submasks, because each allowed position is independently selected or omitted. Enumeration therefore takes updates under constant-cost bitwise operations; has only the empty submask.
New to topics? Read the docs here!