Wednesday, April 13, 2011

Check if a number is power of 2


public boolean isPowerOf2(int num)
{
if((num&(num-1))==0 && num>0)
return true;
else
return false;
}

No comments: