Converting Binary Numbers to their Decimal Equivalent

조회 수: 1 (최근 30일)
Aryan Sondhi
Aryan Sondhi 2020년 4월 7일
댓글: Aryan Sondhi 2020년 4월 7일
I am trying to write a script that will repeadetly prompt users to enter binary numbers that will then be converted to their decimal equivalents. I want the prompt to keep asing users to input new binary numbers until they enter a digit that isn't 0 or 1.
I have tried:
prompt = 'Enter a binary number:';
binary = input(prompt);
str_x = num2str(binary);
y = bin2dec(str_x);
disp(y);
If anyone can please help it would be greatly appreciated as I am new to matlab.

답변 (1개)

KSSV
KSSV 2020년 4월 7일
  댓글 수: 1
Aryan Sondhi
Aryan Sondhi 2020년 4월 7일
thanks for replying, however I am working with integers not floating point numbers

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Data Type Conversion에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by