Easy · Math

Count set bits in number

Given an integer n, return the number of 1 bits in its binary representation; a negative n is counted in its 64-bit two's-complement form (so -1 has 64).

Examples

Example 1

n = 13 (1101)

Output: 3 set bits

Example 2

n = 23 (10111)

Output: 4 set bits

Rebuild it in the studio

Open every published interview problem, solution, scene, and memory room free, with no account.

More Math problems