📘
Number of 1 Bits
EasyBit Manipulation
Given a positive integer, return the number of set bits (1s) in its binary representation (also known as Hamming weight).
Example:
Input:
11
Output:
3
Reasoning:
- First, we convert the input number 11 to its binary representation: 1110=10112
- Then, we count the number of set bits (1s) in the binary representation: 10112 has 3 set bits
- The final output is the count of set bits, which is 3
Constraints:
- 0 <= n <= 2^31 - 1
Editor
Python 3.13.1
Test Results
0/0Run code to see test results.