bool isPowerOfTwo(int n) {
if(n<=0) return false;
if(n&(n-1)) return false;
return true;
}
'&' is binary AND operator. and all the power of 2 numbers are having only one '1' bit. for ex 4 = 100, 8 = 1000 etc.. so if we do AND for n and n-1 one we should get 0, if the numbers is power of 2. because n-1 is always having invert bit of n.. for ex 3 = 011, 7 = 0111. i hope u can get idea from this