question:
set even bits of a number to 0
answer:
question:
set even bits of a number to 0
answer:
hello @aarijrab
a) ![]()
this line will generate a mask whose ith bit will be 1 and rest all bit will be 0.
now
![]()
this line will compute negation i.e it will convert all 0 bit 1 and 1 bit 0.
and becuase mask has only ith bit set and all other are 0, on taking negation it will have ith bit as 0 and rest all bit will be 1.
after this
![]()
when we will take & of mask with n , it will turn of ith bit ,because ith bit of mask is 0 (and of 0 with anything is 0).
so after this line ith bit of n will become 0.
and because i is going from 0 to 31 ,it will set all bit of n to zero.