easyBit Manipulation
Number of 1 Bits
## Problem
Write a function that takes the binary representation of a positive integer and returns the number of **set bits** it has (also known as the [Hamming weight](https://en.wikipedia.org/wiki/Hamming_weight)).
Write a function that takes the binary representation of a positive integer and returns the number of **set bits** it has (also known as the [Hamming weight](https://en.wikipedia.org/wiki/Hamming_weight)).
Examples
Input
n = 11
Output
3
11 in binary is 1011 — three 1-bits.
Input
n = 128
Output
1
128 = 10000000 — one 1-bit.
Input
n = 2147483645
Output
30
0111...101 — thirty 1-bits.
Constraints
1 <= n <= 2^31 - 1
Python
Loading...