text: Program to find whether a given number is power of 2 |  ; Function to check if x is power of 2 ; Driver code
code: #include <iostream> NEW_LINE using namespace std ; bool isPowerofTwo ( long long n ) { if ( n == 0 ) return 0 ; if ( ( n & ( ~ ( n - 1 ) ) ) == n ) return 1 ; return 0 ; } int main ( ) { isPowerofTwo ( 30 ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; isPowerofTwo ( 128 ) ? cout << " Yes STRNEWLINE " : cout << " No STRNEWLINE " ; return 0 ; }