i am not able to understand the output.how 10 and 15 gives 17 set bits
Sir,please expain the problem "playing eith bits"
hello @Abhishmu5
i think question is not clear to u.
the question is asking u to count the total set bits in numbers ranging from a to b.
for example if a=2 and b= 5
then numbers in this range will be 2, 3 ,4. 5
now we need to calculate number of set bits in each of these numbers and take their sum.
2 -> 10 (binary) ( 1 set bit)
3 -> 11 (binary) ( 2 set bit)
4 -> 100 (binary) ( 1 set bit)
2 -> 101 (binary) ( 2 set bit)
now take sum of all set bits i.e 1 + 2 + 1 + 2
so our answer will be 6.
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.