Program to check if a number can be expressed as an even power of 2 or not | C ++ program for the above approach ; Function to check if N can be expressed as an even power of 2 or not ; If N is not a power of 2 ; Bitwise AND operation ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; bool checkEvenPower ( long long int N ) { if ( ( N & ( N - 1 ) ) != 0 ) return false ; N = N & 0x55555555 ; return ( N > 0 ) ; } int main ( ) { int N = 4 ; cout << checkEvenPower ( N ) ; return 0 ; }