Need explanation of a code..

Here is the problem link

Somebody plzz explain the solution of this problem given in the link below. I know this is not my solution, but i want to learn bit manipulation. Tried many self satisfying ways but in the end, they did not lead me to any proper logic. Then searched and found an editorial on bit manipulation on Topcoder here is the link, but this also was not enough. At last now i am on codechef forum.

Here is link to the code…

//