Program to find whether a given number is power of 2 | Method to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver method
function isPowerOfTwo ( x ) { return x != 0 && ( ( x & ( x - 1 ) ) == 0 ) ; } document . write ( isPowerOfTwo ( 31 ) ? " " : " " ) ; document . write ( " " + ( isPowerOfTwo ( 64 ) ? " " : " " ) ) ;