BackeasyBit Manipulation

Number of 1 Bits Solution

Problem Statement

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

Example 1
Input
11
Output
3

Explanation: The binary representation of 11 is 1011 (3 set bits).

Constraints

  • 0 <= n <= 2^31 - 1
Live Compiler
Sign InSign Up
Loading...
Test Cases & Output
Click "Run" to execute