Skip to content
Onsite

Number of 1 Bits

EasyP2Coding

Given a non-negative integer n (treated as an unsigned 32-bit value), return the number of 1 bits in its binary representation.

Example 1

Input
n = 11
Output
3
Why
11 is 1011 in binary, which has three 1 bits.

Example 2

Input
n = 128
Output
1

Example 3

Input
n = 0
Output
0

Constraints

  • 0 <= n <= 2^32 - 1

Hints

Run checks the 3 visible tests, Submit all 10.