Write a program to count the number of 1's in the binary representation of an integer.
The only line of input contains a single integer N.
Output format :
The only line of the output prints the total number of 1.
1 <= N <= 100
9
2
Binary Representation of 9 is 1001.
13
3
Iterate through all bits
O(log(N)), where ‘N’ is the given integer.
Since we are iterating through each bit of binary representation of the given number which is O(log(N)) in size. So the overall time complexity will be O(log(N)).
O(1)
We are using constant extra space.