#K57967. Determine if a Binary Number is a Power of Two
Determine if a Binary Number is a Power of Two
Determine if a Binary Number is a Power of Two
You are given a string representing a binary number. Your task is to check whether the number is a power of two.
A number is a power of two if and only if its binary representation contains exactly one 1 bit. In mathematical notation, if \(s\) is the binary string, then the condition to be a power of two is:
$$\text{count}(1\text{'s in } s) = 1$$For example:
10
represents 2 in decimal, which is \(2^1\) so the answer is True.11
represents 3 in decimal, which is not a power of two so the answer is False.10000
represents 16 in decimal, which is \(2^4\) so the answer is True.
The input is provided via standard input (stdin), and you should output the result via standard output (stdout).
inputFormat
The input consists of a single line containing a non-empty string \(s\) that represents a binary number. The string will only contain characters '0' and '1'.
Example:
1000
outputFormat
Output a single line with True
if the binary string represents a power of two; otherwise, output False
.
Example:
True## sample
10
True