[erlang-questions] string to binary

Igor Goryachev igor@REDACTED
Wed Oct 19 13:15:29 CEST 2011


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


-- 
Igor Goryachev



More information about the erlang-questions mailing list