n ^ (1 << (k-1)) toggles the kth bitn & (n-1) toggles the rightmost one bitn & -n isolates rightmost one bit [ -n is two's complement of n]~n & (n+1) isolates rightmost zero bit
A little bit get inside.... may i know why are you applying only such operation(logic behind bit properties).... bcz if you need to augment any algorithm then you required it. pls
n ^ (1 << (k-1)) toggles the kth bit
ReplyDeleten & (n-1) toggles the rightmost one bit
n & -n isolates rightmost one bit [ -n is two's complement of n]
~n & (n+1) isolates rightmost zero bit
A little bit get inside.... may i know why are you applying only such operation(logic behind bit properties).... bcz if you need to augment any algorithm then you required it. pls
ReplyDelete