text: Program to find whether a given number is power of 2 | Function to check if x is power of 2 ; Driver code
code: function isPowerofTwo ( n ) { if ( n == 0 ) return false ; if ( ( n & ( ~ ( n - 1 ) ) ) == n ) return true ; return false ; } if ( isPowerofTwo ( 30 ) == true ) document . write ( " " ) ; else document . write ( " " ) ; if ( isPowerofTwo ( 128 ) == true ) document . write ( " " ) ; else document . write ( " " ) ;