Playing with bits

Iā€™m unable to understand the question.
How no of set bits between 10 and 15 becomes 17?

hello @samk86676 if you know that how numbers are prepared by powers of 2 in binary system then you will be able to understand the same .
we have binary system as 1 2 4 8 and so on in powers of 2 .
we have to form numbers by using these numbers
like number using binary representation is
suppose number is 6 then binary representation is 0 1 1 0 (4+2=6) .
in this way the numbers are executed by the compiler .
and if you form all the numbers betwenn 10 and 15 in this way and incremnent a counter variable whenever you find 1 then it will be incremented 17 times and the answer will be 17 .
i hope i have cleared your doubt .
Happy Learning !!

1 Like

Thank you for your answer.

@samk86676 yes you understood right in 6 there are 2 set bits and like this you have count number of set bits btw a and b both inclusive.