How to convert binary stream of length 1*524288 to decimal string of length 1*65536?

조회 수: 3 (최근 30일)
There is a need to group 8 bits in the binary stream of 1*524288 to make a decimal string..how to do this using matlab?
  댓글 수: 4
Image Analyst
Image Analyst 2017년 1월 7일
Can you give a short example of how you are getting a longer decimal string from the shorter binary string, like '1101001' goes to '123456787654627838' or something?
Veera Kalyani S
Veera Kalyani S 2017년 1월 8일
If we have k='0000000100000010' then there is a need to get (say)h='1 2'
that is for first 8 bits...'00000001==> 1' for next 8 bits... '00000010==>2'

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

채택된 답변

Stephen23
Stephen23 2017년 1월 8일
편집: Stephen23 2017년 1월 8일
bin2dec probably does most of what you want:
>> bin2dec(reshape('0000000100000010',8,[]).')
ans =
1
2
  댓글 수: 3
Stephen23
Stephen23 2017년 1월 9일
편집: Stephen23 2017년 1월 9일
You seem to have put my code inside a loop, and then inside that loop you access one character of the string at a time, like this:
k(i)
What do you expect to do with one character at a time?
My answer works perfectly for a string with size 1*524288, and it does not need any loops:
>> str = char(randi(48:49,1,524288));
>> vec = bin2dec(reshape(str,8,[]).')
vec =
233
164
146
110
134
162
238
203
etc

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

추가 답변 (0개)

카테고리

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