top of page

Write a program to find whether a number is power of 2?



#include <iostream>

using namespace std;

int main()
{
    int a = 128;
    int b = a-1;
    if(a && !(a & b))
    {
        cout<<"Number is power of 2"<<endl;
    }
    else {
        cout<<"Number is not power of 2"<<endl;
    }
    
}


Comments


bottom of page