Skip to content
BASA DSA

Number of 1 Bits

EasyBit Manipulation

Return the number of one bits in the unsigned 32-bit representation of n.

Example 1

Input
n = 2147483649
Output
2

Explanation

2147483649 sets the highest and lowest bits, giving two.

Example 2

Input
n = 4294967295
Output
32

Explanation

All 32 bits are set in the largest unsigned 32-bit value.

Example 3

Input
n = 0
Output
0

Explanation

Zero has no set bits.

Constraints

  • 0 <= n <= 4294967295

Function contracthammingWeightArguments: json
Loading draft…
SolutionRuns on your device
Loading draft…