int mask = 1<<i ; —> what will be stored in mask;

kyuki int ki capacity 32 bits h to last 3 bits 100 ho jaenge ??

And,

int bit = (n&mask) >0 ? 1:0 ; --> how will this statement work ???

int mask = 1<<i ; —> what will be stored in mask;

kyuki int ki capacity 32 bits h to last 3 bits 100 ho jaenge ??

And,

int bit = (n&mask) >0 ? 1:0 ; --> how will this statement work ???

hello @parth_tyagi

it will set ith bit(counting from 0 and from right to left) to 1 and rest other bit will remain 0.

for example

int mask=1<<3 wil look like

…000001000

note mask has only ith bit set. so if will take its and with any other number.

then result will be positive only when ith bit of that number is set otherwise it will always result in 0.

here we are checking the same if & is > 0 then it means ith bit is set otherwise not set

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.