Dsa
Bit Manipulation
Easy
Count Set Bits in Range
Write a program that calculates the total number of set bits (1s) in the binary representation of all numbers in a given range [L, R] (inclusive). The input consists of two integers, L and R, where 0 <= L <= R <= 10^6. You should print a single integer representing the count of set bits.
Example:
Input:
3 7
Output:
8
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