문제

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