Borrar filtros
Borrar filtros

How to change a sequence of strings into a sequence of binary?

1 visualización (últimos 30 días)
Daniel
Daniel el 13 de Dic. de 2022
Respondida: DGM el 13 de Dic. de 2022
str = 'Daniel';
binary = dec2bin(str);
binary
string = char(bin2dec(binary));
string
This code segment diplays the output as a char array as shown below
binary =
6×7 char array
'1000100'
'1100001'
'1101110'
'1101001'
'1100101'
'1101100'
string =
6×1 char array
'D'
'a'
'n'
'i'
'e'
'l'
But, I want the output to be diplayed as a sequence like Binary = 10000100110000011101110110100111001011101100 and String = 'Daniel'
So, how can I get the output as I want above? Anyone help me.

Respuesta aceptada

DGM
DGM el 13 de Dic. de 2022
Consider:
str = 'Daniel';
binary = dec2bin(str); % need to keep the structure for the moment
string = char(bin2dec(binary)).' % convert and transpose
string = 'Daniel'
binary = reshape(binary.',[],1).' % transpose/reshape to a vector
binary = '100010011000011101110110100111001011101100'

Más respuestas (0)

Categorías

Más información sobre Data Type Conversion en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2019a

Community Treasure Hunt

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

Start Hunting!

Translated by