We’re preparing your current view and syncing the latest data.
Write a function that takes an unsigned integer and returns the number of '1' bits it has (also known as the Hamming weight). For example, the 32-bit integer 11 has binary representation 00000000000000000000000000001011, so the function should return 3.
A single unsigned integer n.
An integer representing the number of '1' bits in n.
The input is a 32-bit unsigned integer.
Example 1
Input
00000000000000000000000000001011
Output
3
Explanation
The binary representation of 11 has three '1' bits.
Example 2
Input
00000000000000000000000010000000
Output
1
Explanation
The binary representation of 128 has only one '1' bit.
Example 3
Input
11111111111111111111111111111101
Output
31
Explanation
The binary representation has thirty-one '1' bits.