Sunday, November 30, 2008

isTwoPower

Very simple and elegant function to test if a number is a power of two.

int isTwoPower(int n){
if( n < 1 )
return 0;
return !(n & (n-1));
}

1 comment:

Sanziana said...

super!
Bine ai venit in blogosfera :D