


Given ‘NUM = 9’
Binary representation of ‘9 = 1001’, so there are 2 times 1's present.
Print ‘2’ as the answer.
The first line contains a single integer ‘T’ representing the number of test cases.
The only line of each test case contains a single integer ‘NUM’ representing an integer whose number of bits which are ‘1’ in the binary representation you need to print.
For each test case print the number of bits ‘1’ in binary representation.
Print the output of each test case in a separate line.
You do not need to print anything; it has already been taken care of. Just implement the function.
1 <= T <= 10000
1 <= NUM <= 10^9
Time Limit: 1sec
We will do the process till ‘NUM’ is greater than 0:
Approach: Instead of checking every bit of the number, we can repeatedly flip the least significant bit which is ‘1’ to ‘0’. Each time this thing happens we increase ‘ANS’ by 1. The reason this algorithm works is each time it runs it only flips the least significant bit which is 1. Therefore each time it runs it makes 1 bit ‘1’ into zero. Our answer will be the total number of times it runs before ‘NUM’ becomes zero.
We can do it as follows: