this simple code is to check if a given number is a poer of two or not method if a number is a power of two then its binary representation is 2k ex 4 22 100 k 2 8 23 1000 k 3 16 24 10000 k 4 assume that n is a power of two then n1n will be zero ex n 8 1000 n1 7 0111 performing bit and operation between both then nn1 0000 n 12 1100 n1 11 1011 performing bit and operation between both then nn1 1000 conclusion the result of the above bit and operation will be zero only if the given number is a pwoer of two note since python considers 0 as false then we are gonna return the inversion of the result i e return notnn1 but if n 0 the result will be zero indicating that 0 is a power of 2 wich is not true so to fix that we are going to perform an extra logical and operation with the oreginal number
def pow_of_two(n):
  return(n and (not(n&(n-1))))

for i in range(20):
  if pow_of_two(i):
    print(f"{i} is a power of 2.")
  else:
    print(f"{i} is NOT a power of 2.")