0
Q:

check whether a number is power of 2 or not

#include <bits/stdc++.h> 
using namespace std; 
#define bool int  
  
/* Function to check if x is power of 2*/
bool isPowerOfTwo (int x)  
{  
    /* First x in the below expression is for the case when x is 0 */
    return x && (!(x&(x-1)));  
}  
  
/*Driver code*/
int main()  
{  
    isPowerOfTwo(31)? cout<<"Yes\n": cout<<"No\n";  
    isPowerOfTwo(64)? cout<<"Yes\n": cout<<"No\n";  
    return 0;  
}  
  
// This code is contributed by rathbhupendra 
0

New to Communities?

Join the community