Dsa
Bit Manipulation
Easy
Count Set Bits
Write a program that takes an integer as input and outputs the count of set bits (1s) in its binary representation.
Input format:
- A single integer N (0 <= N <= 10^9)
Output format:
- An integer representing the count of set bits.
Example:
Input:
5
Output:
2
(The binary representation of 5 is '101', which has 2 set bits.)
Key concepts
bit_manipulationcounting
Practise this out loud — free
Start a mock interview on THIS exact question — a voice AI interviewer opens with it, pushes back like a real onsite, then hands you an instant scorecard.
🎙 Practise this question now