Search This Blog

Sunday, August 8, 2010

evaluate whether a number is integer power of 4

Programmer Question

The following function is claimed to evaluate whether a number is integer power of 4. I do not quite understand how it works?



bool fn(unsigned int x)
{
if ( x == 0 ) return false;
if ( x & (x - 1) ) return false;
return x & 0x55555555;
}


Find the answer here

No comments:

Post a Comment

Related Posts with Thumbnails