سؤال

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

هل كانت مفيدة؟

المحلول

I'd try binary comprehensions

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

For instance

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

نصائح أخرى

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"
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top