Pregunta

I have tried to use bitstring but with no success

I need to convert a String to (String of bits), 8 bits for each char

For example:

"hi" = "0110100001101001"

Thanks

¿Fue útil?

Solución

I'd try binary comprehensions

[C + $0 || <<C:1>> <= list_to_binary(String)]

For instance

[C + $0 || <<C:1>> <= list_to_binary("hi")].
"0110100001101001"

Otros consejos

One way to do this is to use formatting using io_lib:format

lists:flatten([io_lib:format("~8.2.0B", [Char]) || Char <- String]).
"0110100001101001"
Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top