%%% Copyright (c) 2014-2015, NORDUnet A/S. %%% See LICENSE for licensing information. -module(hex). -export([bin_to_hexstr/1,hexstr_to_bin/1]). -spec bin_to_hexstr(binary()) -> string(). bin_to_hexstr(Bin) -> mochihex:to_hex(Bin). hexstr_to_bin(S) -> hexstr_to_bin(S, []). hexstr_to_bin([], Acc) -> list_to_binary(lists:reverse(Acc)); hexstr_to_bin([X,Y|T], Acc) -> {ok, [V], []} = io_lib:fread("~16u", [X,Y]), hexstr_to_bin(T, [V | Acc]).