Doubt in a statement

i have seen this statemet many a times, but dont know properly why and when to use …plss help

for(int i=0;i<31;i++){
if(k&(1<<i)){
…}

hi @aman17nov1999
(k&1) is used to determine if k is odd or not
if k is odd, then its last bit will be 1 and k & 1 will also be 1 which will result in boolean true
if k is even, then its last bit will be 0 and k & 1 will be 0 which will result in boolean false

Is that what you mean or is it something else?

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.