Write a function named “isBinaryNumber” that accepts a C-string. It returns true if the C-string contains a valid binary

Business, Finance, Economics, Accounting, Operations Management, Computer Science, Electrical Engineering, Mechanical Engineering, Civil Engineering, Chemical Engineering, Algebra, Precalculus, Statistics and Probabilty, Advanced Math, Physics, Chemistry, Biology, Nursing, Psychology, Certifications, Tests, Prep, and more.
Post Reply
answerhappygod
Site Admin
Posts: 899603
Joined: Mon Aug 02, 2021 8:13 am

Write a function named “isBinaryNumber” that accepts a C-string. It returns true if the C-string contains a valid binary

Post by answerhappygod »

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)
Join a community of subject matter experts. Register for FREE to view solutions, replies, and use search function. Request answer by replying!
Post Reply