Number of 1 Bits Problem
Number of 1 Bits Problem — ExecCode Easy DSA Practice
Solve the Number of 1 Bits problem on ExecCode. Free online easy DSA practice in Bit Manipulation. Write and run code in Java, C++, Python — no signup required to run.
Problem description
Write a function that takes an unsigned 32-bit integer and returns the number of "1" bits it has, also known as the Hamming weight, using Brian Kernighan's bit trick.
Examples
Input n = 11; Output 3. Input n = 128; Output 1. Input n = 4294967293; Output 31
Constraints
The input is a 32-bit unsigned integer
Practice Number of 1 Bits free on ExecCode. Browse DSA problems, topic map, and placement guides.