Algorithms Playbook
← All problems
EasyBit manipulation →Similar to: Number of 1 Bits

Count the lit bits

Problem

Given a non-negative integer n, return the number of 1 bits in its binary representation.

Examples

Input: 11 (1011)

Output: 3

Input: 128 (10000000)

Output: 1

Hints

    Try it first. Every hint reveals a bit more.

    Solution