Skip to content

Instantly share code, notes, and snippets.

@KOUCHANG
Created May 19, 2015 16:53
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 KOUCHANG/e372b23936db2c47dc64 to your computer and use it in GitHub Desktop.
Save KOUCHANG/e372b23936db2c47dc64 to your computer and use it in GitHub Desktop.
-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