PIXELBANKv8.2.1
Menu

Number of 1 Bits

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=1011211_{10} = 1011_2
  • Then, we count the number of set bits (1s) in the binary representation: 101121011_2 has 3 set bits
  • The final output is the count of set bits, which is 33

Constraints:

  • 0 <= n <= 2^31 - 1
Editor

Test Results

0/0
Run code to see test results.