Set Bits Counter

Bit Manipulation Coding Interview Easy Algorithm

Set Bits Counter

Write a function that takes a non-negative integer and returns the count of bits that are set to 1 in its binary representation.

For example:

  • Input: 9 (binary: 1001)
  • Output: 2

Requirements

  • Your solution should handle the case when the number is 0.
  • Aim to implement an efficient solution using bit manipulation.

Historical Note

On March 6, several significant events in technology and computing have taken place over the years. Today, put your bit manipulation skills to the test and contribute to this legacy of innovation!

Input/Output

  • Input: An integer n (n >= 0).
  • Output: An integer representing the count of set bits in n's binary representation.

Good luck!