how do i verify input is only zeros and 1's
Show older comments
i am trying to figure out how to check if a number entered by a user is only zeros and ones (checking if its binary). I am not allowed to use a table or matrix
this is what I have, but doesn't seem to work
number = input('please enter a number:', 's')
if all(ismember(number,['0' '1'])) fprintf('this is a binary number.'); else fprintf('this is not a binary number.'); end
Accepted Answer
More Answers (0)
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!