is_power_of_two
is_power_of_two(
value: int ,
)-> ‘bool’
Return True when value is a positive power of two.
Powers of two have exactly one set bit in their binary representation. Subtracting one flips that bit and all lower bits, so value & (value - 1) is zero only when value had a single set bit. The value > 0 check excludes zero and negative values.
Parameters
| Parameter | Description |
|---|---|
| value | The value to test. |