Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
-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
You can’t perform that action at this time.