Domanda

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

È stato utile?

Soluzione

I'd try binary comprehensions

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

For instance

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

Altri suggerimenti

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"
Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top