Number of 1 Bits
Write a function that takes the binary representation of an unsigned integer and returns the number of 1 bits it has (also known as the Hamming weight).

30:00

Number of 1 Bits
easy
Topics
Companies

Write a function that takes the binary representation of an unsigned integer and returns the number of 1 bits it has (also known as the Hamming weight).

Example 1:
Input: 11
Output: 3
Constraints:
  • The input must be a binary string of length 32.

  • 0n23110 \leq n \leq 2^{31} - 1

Input
arr =11

Count 1 bits

n

11

000028000024000020000016000012000080000410110

1-bits count: 0

Variables
VariableValue
n11
DepthFunction Call
Stack empty
0/5