Borrar filtros
Borrar filtros

How to convert a string to a 8 bit Ascii one row binary vector?

2 visualizaciones (últimos 30 días)
Hello everyone. I have for example the string:"abcd" i want to convert it to "01100001011000100110001101100100" (see the apendded zeros). as a logical vector.
thanks!

Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 17 de Ag. de 2016
Editada: Azzi Abdelmalek el 17 de Ag. de 2016
s='abcd'
p=dec2bin(double('abcd'),8)'
out=p(:)'
  2 comentarios
Jack Day
Jack Day el 17 de Ag. de 2016
thank you Azzi. But unfortunately, dec2bin doesnt convert well the full ascii table. 'abcd' is converted well, but ╞ , ╨ etc. does not.
i need a convertion of 8 bit ascii of all the characters. thanks
Stephen23
Stephen23 el 17 de Ag. de 2016
Editada: Stephen23 el 17 de Ag. de 2016
@Jack Day: ╞ , ╨ are not in the ASCII character set. ASCII only uses seven bits.
Those characters are in the Unicode "Box Drawing" set, which starts at 0X2500 (9472 decimal). There is no way that these can fit into seven (or even eight) bits!
To convert into a logical vector with eight bits per character, as the question requires:
reshape(dec2bin(+'abcd',8)',1,[])=='1'

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