Created
March 22, 2011 14:43
-
-
Save monkeydom/881313 to your computer and use it in GitHub Desktop.
Simple Binary / List to lowercase hex functions using binary comprehensions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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