Skip to content
QuantReadySign In
#098easyBit Manipulation

Active Signal Bits

Time Limit: 2sMemory: 256MB

Problem

A quantitative trading system encodes active market signals as bits in an unsigned integer. Each bit position represents a different signal — a 1 means the signal is active, 0 means inactive.

Given a non-negative integer, count the number of active signals (set bits / 1-bits) in its binary representation.

Input Format

A single non-negative integer n.

Output Format

A single integer — the count of 1-bits.

Examples

Example 1
Input(A single non-negative integer n.)
11
Output
3

11 in binary is 1011, which has three 1-bits.

Example 2
Input(A single non-negative integer n.)
128
Output
1

128 is 10000000 in binary — one set bit.

Constraints

  • 0 ≤ n ≤ 2^31 - 1
Loading interactive editor…