Created
May 19, 2015 16:53
-
-
Save KOUCHANG/e372b23936db2c47dc64 to your computer and use it in GitHub Desktop.
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
-module(hexlify_sample). | |
-export([hexlify/1]). | |
-define(TOHEX(X), | |
begin | |
<<X1:1, X2:1, X3:1, _:1>> = <<X:4>>, | |
TenF = X1 band X2 bor X1 band bnot X2 band X3, | |
X + (1 - TenF) * $0 + TenF * ($A - 10) | |
end). | |
hexlify(Binary) -> | |
<< <<?TOHEX(X), ?TOHEX(Y)>> || <<X:4, Y:4>> <= Binary>>. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment