Binary String to ASCII

19 visualizaciones (últimos 30 días)
Jared
Jared el 23 de Oct. de 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.

Respuesta aceptada

Matt Fig
Matt Fig el 23 de Oct. de 2012
Editada: Matt Fig el 23 de Oct. de 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 comentarios
Jared
Jared el 23 de Oct. de 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 el 23 de Oct. de 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)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Characters and Strings en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by