conversion of binary to decimal

binary=1011 decimal=bin2dec('binary')
this code shows a error - Error using bin2dec Binary string may consist only of characters 0 and 1
Is there is method for conversion of binary to decimal through passing a variable which consists binary numbers?????

1 Commento

code matlab how to convert from binary to decimal

Accedi per commentare.

 Risposta accettata

David Goodmanson
David Goodmanson il 29 Mar 2017
Modificato: David Goodmanson il 29 Mar 2017
Hi ablaze, Your code has bin2dec trying to convert a string containing the word 'binary'. Try
a = '1011'
bin2dec(a)

3 Commenti

Guillaume
Guillaume il 29 Mar 2017
Modificato: Guillaume il 29 Mar 2017
Note that if the input is indeed numerical as shown, then
binary = 1011;
decimal = bin2dec(num2str(binary));
would work up to 15 bits. After that you're above the maximum integer value that can be stored accurately in a double (see flintmax)
It is indeed much safer to store this binary number as a string, which does not have any limit on the number of bits.
ablaze
ablaze il 29 Mar 2017
thank u
Hi, how can I convert Hexadecimal to excess 3 code using Matlab?

Accedi per commentare.

Più risposte (0)

Categorie

Scopri di più su Convert Image Type in Centro assistenza e File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by