[erlang-questions] string to binary

Wes James <>
Wed Oct 19 16:09:06 CEST 2011


On Wed, Oct 19, 2011 at 5:15 AM, Igor Goryachev <> wrote:
> On Wed, Oct 19, 2011 at 03:02, Wes James wrote:
>
>> Is there a way to get "00:11:22:33:44:55" in to this format
>> <<16#00,16#11,16#22,16#33,16#44,16#55>>?
>>
>> I can do string:tokens(S) to split the string (list) up, but how do
>> you put back in <<16#....>>  format?
>
> 1> list_to_binary([element(2, io_lib:fread("~16u", X)) || X <- string:tokens("00:11:22:33:44:55", ":")]).
> <<0,17,34,51,68,85>>
> 2> <<0,17,34,51,68,85>> == <<16#00,16#11,16#22,16#33,16#44,16#55>>.
> true


Thanks all for responding.  I appreciate it.

-wes



More information about the erlang-questions mailing list