Converting Binary Numbers to their Decimal Equivalent

5 visualizaciones (últimos 30 días)
Aryan Sondhi
Aryan Sondhi el 7 de Abr. de 2020
Comentada: Aryan Sondhi el 7 de Abr. de 2020
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.

Respuestas (1)

KSSV
KSSV el 7 de Abr. de 2020
  1 comentario
Aryan Sondhi
Aryan Sondhi el 7 de Abr. de 2020
thanks for replying, however I am working with integers not floating point numbers

Iniciar sesión para comentar.

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by