Filter löschen
Filter löschen

Binary String to ASCII

9 Ansichten (letzte 30 Tage)
Jared
Jared am 23 Okt. 2012
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.

Akzeptierte Antwort

Matt Fig
Matt Fig am 23 Okt. 2012
Bearbeitet: Matt Fig am 23 Okt. 2012
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 Kommentare
Jared
Jared am 23 Okt. 2012
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 am 23 Okt. 2012
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)

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Characters and Strings finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by