Skip to content

Instantly share code, notes, and snippets.

@monkeydom
Created March 22, 2011 14:43
Show Gist options
  • Save monkeydom/881313 to your computer and use it in GitHub Desktop.
Save monkeydom/881313 to your computer and use it in GitHub Desktop.
Simple Binary / List to lowercase hex functions using binary comprehensions
to_hex(List) when is_list(List) ->
to_hex(iolist_to_binary(List));
to_hex(Binary) when is_binary(Binary) ->
<< <<(to_digit(Nibble1)):8,(to_digit(Nibble2)):8>> || <<Nibble1:4,Nibble2:4>> <= Binary >>.
to_digit(N) when N < 10 -> $0 + N;
to_digit(N) -> $a + N-10.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment