In c++ I am searching for an efficient algorithm to generate all integers such that their binary representation is a subset of a set which is given by the binary representation of integer N. By efficient I mean that I don't want to for-loop through all integers smaller than N to check whether they are subsets, mainly because N could be very large.
An idea I had was to generate all possible subsets of an integer corresponding to the Hamming weight of N and then shift them to the correct positions using <<, but I am so far failing to find a good way how to do this.
Example:
For set 110100 given by integer N=52 all possible subsets would be:
{000100,010000,010100,100000,100100,110000}
corresponding to integers {4,16,20,32,36,48}, which is what I want to generate.