Number of set bits
Statement
Goal
Given a nonnegative integer x, count the number of set bits (bits which are a 1) in its binary representation.For example, 31 = 11111 has 5 set bits.
Input
Line 1: An integer x
Output
Line 1: The number of set bits in the binary representation of x
Constraints
0 ≤ x < 2^31
Example
Input
31
Output
5
Game modes
Fastest, Shortest, Reverse
Test cases
Test 1 Test
Input
31
Output
5
Validator 1 Validator
Input
63
Output
6
Test 2 Test
Input
32
Output
1
Validator 2 Validator
Input
65536
Output
1
Test 3 Test
Input
0
Output
0
Validator 3 Validator
Input
2
Output
1
Test 4 Test
Input
42
Output
3
Validator 4 Validator
Input
100
Output
3
Test 5 Test
Input
2147483647
Output
31
Validator 5 Validator
Input
16777215
Output
24
Test 6 Test
Input
1
Output
1
Validator 6 Validator
Input
3
Output
2
Solution language
Solution
Stub generator input