Logarithm tricks for Competitive Programming | Function to check if the number is a power of two ; Driver Code
function isPowerOfTwo ( n ) { return ( Math . ceil ( Math . log ( n ) / Math . log ( 2 ) ) == Math . floor ( Math . log ( n ) / Math . log ( 2 ) ) ) ; } let N = 8 ; if ( isPowerOfTwo ( N ) ) { document . write ( " " ) ; } else { document . write ( " " ) ; }