A ground-control status register is transmitted as a single non-negative integer n. Each bit of n, when written in binary, represents one onboard subsystem: a 1 bit means that subsystem is currently ACTIVE, and a 0 bit means it is inactive.
Given n, report how many subsystems are currently active.
Line 1: a single integer n.
A single integer: the number of 1 bits in the binary representation of n.
Example 1
Input
5
Expected
2
Explanation
5 in binary is 101, which has two 1-bits, so 2 subsystems are active.
Example 2
Input
0
Expected
0
Explanation
0 has no 1-bits, so 0 subsystems are active.
Ready to solve this?
Sign in to open the editor, run your code against the sample tests, and submit against the full test suite.
Sign in to solve →