Effacer les filtres
Effacer les filtres

ASCII to Binary Bit Stream

9 vues (au cours des 30 derniers jours)
Jared
Jared le 23 Oct 2012
I am trying to convert an ASCII test string to a binary bit stream for output to an external device down the line. As a test, I create a text string:
ascii_msg='Test.';
As expected, a 5x7 char array is created. I'm not sure where to go from here. I use:
bin_msg=cellstr(dec2bin(ascii_msg));
And end up with a 12x1 cell array. I would like to get this in a 35x1 cell array, with each cell containing 1 bit. What is the best way to go about this?

Réponse acceptée

Walter Roberson
Walter Roberson le 23 Oct 2012
bin_msg = num2cell(reshape( dec2bin(ascii_msg).', [], 1));
Are you sure you need one cell per bit, and just having one bit per array element is not good enough? To get one bit per array element, leave off the num2cell() layer of the above.

Plus de réponses (0)

Catégories

En savoir plus sur Characters and Strings dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by