text: Program to find whether a given number is power of 2 |  ; Function to check if x is power of 2 ; First x in the below expression is for the case when x is 0 ; Driver program to test above function
code: #include <stdio.h> NEW_LINE #define bool  int NEW_LINE bool isPowerOfTwo ( int x ) { return x && ( ! ( x & ( x - 1 ) ) ) ; } int main ( ) { isPowerOfTwo ( 31 ) ? printf ( " Yes STRNEWLINE " ) : printf ( " No STRNEWLINE " ) ; isPowerOfTwo ( 64 ) ? printf ( " Yes STRNEWLINE " ) : printf ( " No STRNEWLINE " ) ; return 0 ; }