Power of two

Write codeEasy10 min

Your task

A graphics engine requires every texture dimension to be an exact power of two (1, 2, 4, 8, 16, ...). Given an integer n (which may be zero or negative), return true if n is a power of two and false otherwise. Solve it with bit operations rather than a loop of divisions: a power of two has exactly one set bit in its binary representation. For example, 16 returns true and 24 returns false.

Examples

is_power_of_two(n: int) -> bool
Example 1
Inputis_power_of_two(16)
OutputTrue
Example 2
Inputis_power_of_two(24)
OutputFalse