binary to decimal conversion.......need ans immidiately plzzzzzzzzzzz

1 vue (au cours des 30 derniers jours)
Talat
Talat le 6 Mai 2011
hello! I have a string of binary suppose a binary string of 2000 bit. A=[0 0 0 0 1 1 0 1 1 0 1 0 0 ............so on] I wana to convert it into decimals. though i use function B=bin2dec(A, 8). but it returns me error. i wana to convert each 8-bits into decimal number. plz help me how should i do it. Thanks

Réponse acceptée

Teja Muppirala
Teja Muppirala le 6 Mai 2011
sum(bsxfun(@times,reshape(A,8,[]), 2.^(7:-1:0)'))
  3 commentaires
Teja Muppirala
Teja Muppirala le 7 Mai 2011
Good catch. Much better.
Teja Muppirala
Teja Muppirala le 7 Mai 2011
Same without transposes:
2.^(7:-1:0)*reshape(A,8,[])

Connectez-vous pour commenter.

Plus de réponses (2)

RoJo
RoJo le 6 Mai 2011
bin2dec takes a binary string as input argument.
So you can convert A into 8 bit strings and then call bin2dec
For example A1 = '00001101' B1 = bin2dec(A1)

Andrei Bobrov
Andrei Bobrov le 6 Mai 2011
variant
bin2dec(num2str(reshape([A,zeros(1,8-rem(length(A),8))],[],8)))
  1 commentaire
Walter Roberson
Walter Roberson le 6 Mai 2011
bin2dec(char('0'+reshape([A,zeros(1,8-rem(length(A),8))],[],8)))

Connectez-vous pour commenter.

Catégories

En savoir plus sur Get Started with MATLAB dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by