Alternate for counting bits

can we use any other logic to count the bits
like the condition we used to check it as set or not
if(n&(n<<i)) where ith bit
then we can increment the count

so what is the best-optimized solution like using the condition discussed in this video or the condition I mentioned in this question

hi @discobot,
refer

Hi! To find out what I can do, say @discobot display help.

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.