I came across a piece of code for finding the smallest power of 2 greater than a 32-bit integer n...
n+=(n==0);
n--;
n|=n>>1;
n|=n>>2;
n|=n>>4;
n|=n>>8;
n|=n>>16;
n++;
Now how does it work? I tried printing the number in base-2 after every step for n=100, but it didn't make much sense. What's the logic behind it?