Here's your first problem: count how many bits are set to 1 in the binary representation of a positive integer .
For example, if , the answer is 3 (three 1s). If , the answer is 3.
Before reading the solution, think: how would you check each bit? How many bits do you need to check?