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

조회 수: 3 (최근 30일)
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

채택된 답변

Teja Muppirala
Teja Muppirala 2011년 5월 6일
sum(bsxfun(@times,reshape(A,8,[]), 2.^(7:-1:0)'))
  댓글 수: 3
Teja Muppirala
Teja Muppirala 2011년 5월 7일
Good catch. Much better.
Teja Muppirala
Teja Muppirala 2011년 5월 7일
Same without transposes:
2.^(7:-1:0)*reshape(A,8,[])

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

추가 답변 (2개)

RoJo
RoJo 2011년 5월 6일
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 2011년 5월 6일
variant
bin2dec(num2str(reshape([A,zeros(1,8-rem(length(A),8))],[],8)))
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 5월 6일
bin2dec(char('0'+reshape([A,zeros(1,8-rem(length(A),8))],[],8)))

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

카테고리

Help CenterFile Exchange에서 Image Processing and Computer Vision에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by