Erlang io:formatting a binary to hex

Viewed 17056

Can I format an Erlang binary so that each byte is written in hex? I.e.,

> io:format(???, [<<255, 16>>]).
<<FF, 10>>

I don't see an obvious way to do it in io:format documentation, but perhaps I am simply missing one? Converting a binary to list and formatting its elements separately is too inefficient.

8 Answers

As of OTP24, there is

1> binary:encode_hex(<<1,2,3,4,5,6,255>>).
<<"010203040506FF">>
Related