Maybe better explained with an example:
Binary number B = 1100, every number less than B is 1010, 1001, 0110, 0101, 0011. (With 2 bits == 1)
So the total ways of expressing the number B and all numbers less than B that contains 2 bits == 1 is 6, or 3+2+1.
I suspect this is a Combinations problem, but my math skills are kind of rusty, and I cannot deduce a consistent formula for different binary numbers.
I have done my search on the web, but could not find anything that gave me an answer to this particular problem.