I am looking for an efficient way to iterate over all n bit non-negative integers which have at most k bits set by flipping one bit at a time.
What is the minimum number of bit flips I need to do to iterate over all n bit non-negative integers with at most k bits set?
I know that if k = n, that is we want to iterate over all n bit non-negative integers then we can use a Gray code. This has the great property that you only ever change one bit to get a new number. However this will typically go via integers with more than k bits if k < n.