Skip to content

Latest commit

 

History

History
39 lines (28 loc) · 669 Bytes

File metadata and controls

39 lines (28 loc) · 669 Bytes
  bool isPowerOfTwo(int n) {
            for(int i=0;i<=30;i++)
            {
                if(pow(2,i) ==n)
                    return true;

                else if(pow(2,i) > n)
                    return false;    
            }
            return false;
bool isPowerOfTwo(int n) {
        
        if(n==0) return 0;
        while(n%2==0)
            n/=2;
        
        return n==1;
    }
bool isPowerOfTwo(int n) {
        
        if(n<=0) return 0;

        if((n &(n-1))==0)
            return 1;
        return 0;
    }