Skip to content

Instantly share code, notes, and snippets.

@alco
Last active August 29, 2015 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save alco/11196658 to your computer and use it in GitHub Desktop.
Save alco/11196658 to your computer and use it in GitHub Desktop.
defmodule B do
def bin_to_hex(data) do
for <<hi::4, lo::4 <- data>>,
into: <<>>,
do: <<hex_digit(hi), hex_digit(lo)>>
end
defp hex_digit(n) when n < 10, do: n + ?0
defp hex_digit(n), do: n-10 + ?a
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment