binary to ascii converting

조회 수: 42 (최근 30일)
homa maleki
homa maleki 2020년 1월 1일
댓글: Star Strider 2020년 1월 1일
Hi, how can I convert a 96 bit binary string to the 8-bit ascii? I should find a sentence

채택된 답변

Star Strider
Star Strider 2020년 1월 1일
편집: Star Strider 2020년 1월 1일
Try this:
binstr = char(randi([0 1]+'0', 1, 96)); % Create (Random) Binary Character Vector
binstr8 = reshape(binstr, [], 8); % Reshape To (12x8) Character Array
binmtx = bin2dec(binstr8); % Convert Binary Character Array To Decimal Column Vector
chrmtx = char(binmtx); % Convert Decimal Column Vector To Character Column Vector
You can combine these into one line if you want to. I kept them separate to demonstrate how the code works.
EDIT — (1 Jan 2020 at 18:13)
chrmtx = @(x) char(bin2dec(reshape(x(:).',[],8))); % One-Line Anonymous Function Version Of This Code
Out = chrmtx(binstr);
  댓글 수: 10
homa maleki
homa maleki 2020년 1월 1일
Thank you so much it is working now
Star Strider
Star Strider 2020년 1월 1일
My pleasure.
If my Answer helped you solve your problem, please Accept it!

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

추가 답변 (0개)

카테고리

Help CenterFile Exchange에서 Characters and Strings에 대해 자세히 알아보기

제품


릴리스

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by