Playing with bits

while(j>0)
{
c+=(1&j);
j=j>>1;
}
i++;
}
whats the logic behind this code to count set bits
i.e jis number be setbits cnt karne ho usse 1 ke saath and karo aur baad mai right shift karo jaab taak vo zero naa ho jaye

hello @jatinupadhyay786
yeah basically .
everytime we are fetching rightmost bit and then it is once we r incrementing our count.
and then we r performing right shifitng to get next bit at right most position.

bahi lekin pata kasie chalega ki aise karna hoga ye much discussion forum se pata chala tareeak

sayad ye bit manipulation wali playlist mein cover ho rakha hai (not sure)

to ek baar dekh lo

ussme nahi tha toh matlab inn cheezo ko yaad rakhna hoga??

ha mind mein rakho ise .
jayda se jayda questions practice karo.
taaki padha hua bhulo nahi

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.