Write a function named “isBinaryNumber” that accepts a C-string. It returns true if the C-string contains a valid binary
Posted: Fri May 20, 2022 6:21 pm
Write a function named “isBinaryNumber” that accepts a C-string.
It returns true
if the C-string contains a valid binary number and false otherwise.
The binary
number is defined as a sequence of digits only 0 or 1. It may
prefix with “0b”
followed by at least one digit of 0 or 1.
For example, these are the C-strings with their expected return
values
“0” true
“1” true
“0b0” true
“0b1” true
“0b010110” true
“101001” true
“” false
“0b” false
“1b0” false
“b0” false
“010120” false
“1201” false
Note: this function cannot use the string class or string functions
such as strlen. It
should only use an array of characters with a null terminating
character (C-string)
It returns true
if the C-string contains a valid binary number and false otherwise.
The binary
number is defined as a sequence of digits only 0 or 1. It may
prefix with “0b”
followed by at least one digit of 0 or 1.
For example, these are the C-strings with their expected return
values
“0” true
“1” true
“0b0” true
“0b1” true
“0b010110” true
“101001” true
“” false
“0b” false
“1b0” false
“b0” false
“010120” false
“1201” false
Note: this function cannot use the string class or string functions
such as strlen. It
should only use an array of characters with a null terminating
character (C-string)