If you had a "complete" sequence of numbers from 0 to 2 ^ N-1, then the number of bits set at each bit position would be equal to (and equal to (2 ^ N) / 2).
If only one number is missing, then 1 bit corresponds to bit positions that are short of one bit.
Note that this only works for grades 2, but perhaps you can develop more complex formulas for "odd" counts.
Hot licks
source share