Number of 1 Bits - aloalgo.com

Number of 1 Bits

Easy
New!

You are given a non-negative integer, n.

Your task is to count the total number of set bits (1s) in the binary representation of n.

You may assume that:

  • n is a non-negative integer.

Return the count of set bits.

Example 1

Input
0
Output
0
Explanation:

The binary representation of 0 is 0, which has zero 1 bits.

Example 2

Input
85
Output
4
Explanation:

The binary representation of 85 is 1010101, which has four 1 bits.

Example 3

Input
255
Output
8
Explanation:

The binary representation of 255 is 11111111, which has eight 1 bits.

Loading...

Hello! I am your ✨ AI assistant. I can provide you hints, explanations, give feedback on your code, and more. Just ask me anything related to the problem you're working on!