フィルターのクリア

Binary String to ASCII

22 ビュー (過去 30 日間)
Jared
Jared 2012 年 10 月 23 日
If I have a character array of binary numbers, representing the ASCII code of a text string, how do I convert those numbers back to the text representation? The character array is 35x1, which should result in 5 ascii characters. I tried:
ascii_msg_decoded=char(bin2dec(reshape(bin_msg,[],7)));
It does convert to ASCII, but the characters are not correct.

採用された回答

Matt Fig
Matt Fig 2012 年 10 月 23 日
編集済み: Matt Fig 2012 年 10 月 23 日
How did you do it? This seems to work.
M = 'Hello';
% Now encode:
Mbinlong = reshape(dec2bin(double(M),7).',[],1)
% Now decode:
mess = char(bin2dec(reshape(Mbinlong,7,[]).').')
  3 件のコメント
Jared
Jared 2012 年 10 月 23 日
I should also add, that this received bit stream will not be stored as a character array like Mbinlong is above. It will be, in the case of this example, a 1x35 cell. This code will work still, with the intermediate step of converting that 1x35 cell into the character array that looks like Mbinlong. How would I do that?
Matt Fig
Matt Fig 2012 年 10 月 23 日
Does each cell of the cell array have a message in it? If so, just access each cell one at a time.
M = {'Hello','Goodbye'};
% Now encode each message:
Mb = cellfun(@(x)reshape(dec2bin(x,7).',[],1),M,'Un',0);
% Now decode each message:
mess = cellfun(@(x)char(bin2dec(reshape(x,7,[]).').'),Mb,'Un',0)

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeCharacters and Strings についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by