Count Set Bits (Hamming Weight)

Practice this coding question on Coding Gurukul.

Problem statement

A permissions register stores enabled features as one-bits in a 32-bit unsigned integer. The dashboard needs the number of enabled features, regardless of which bit positions hold them. Your task Count the number of set bits in the binary representation of n. Important details Count bits, not decimal digits or the highest occupied bit position. Leading zero bits do not contribute. Zero has no set bits, and an unsigned 32-bit value can require a wider signed type when read in languages without unsigned integers. Worked example The value 13 is binary 1101, containing three one-bits. Therefore the feature count is 3.

Input format

One unsigned integer n in decimal.

Output format

Print the number of one-bits.

Constraints

0 <= n <= 4294967295.

Sample input

13

Sample output

3

Sign in to run or submit a solution in C++, Java or Python.