Question

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

Was it helpful?

Solution

I'd try binary comprehensions

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

For instance

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

OTHER TIPS

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"
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top