Suppose we have a number n. We have to check whether all bits are set (1) for the given number n or not.
So, if the input is like n = 255, then the output will be True as the binary representation of 255 is 11111111.
To solve this, we will follow these steps −
Let us see the following implementation to get better understanding −
def solve(number): if number == 0: return False while number > 0: if (number & 1) == 0: return False number = number >> 1 return True n = 255 print(solve(n))