Confusion in implementation

#include
using namespace std;
int main() {
int n;
int a,b,r;
cin>>n;
while(n>0)
{
cin>>a>>b;
r=(a&(1<<b))>0?1:0;
cout<<r;
n–;
}
return 0;
}

@naaz the number of set bits in a number are the number of 1 in its binary representaion. The statement you have written, r=(a&(1<<b))>0?1:0; this will not be able to count the set bits in ALL numbers in the range [a, b].
You have to find the number of set bits in individual numbers, and then add it to the ans, and when you have processed all numbers from [a, b] print that answer.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.