Erlang io:formatting a binary to hex

后端 未结 7 695
难免孤独
难免孤独 2020-12-29 06:06

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

> io:format(???, [<<255, 16>>]).
<>
7条回答
  •  心在旅途
    2020-12-29 06:15

    Improving upon @hairyhum

    This takes care of zero paddings << <> ||<> <= Id, Y <- integer_to_list(X,16)>>

    reverse transformation <<<> || <> <= Id,Z <- [binary_to_integer(<>,16)]>>, %%hex to binary

提交回复
热议问题