[erlang-questions] Formatting question
Gaspar Chilingarov
nm@REDACTED
Sat Aug 4 22:58:27 CEST 2007
> Question no. 2: the solution somehow looks ugly. That cannot be right.
> Does anyone have a more succinct solution for bin2hex ?
>
I use this code (probably copied from http_util or something like this).
byte2hex(X) -> % {{{
{nibble2hex(X bsr 4), nibble2hex(X band 15)}. % }}}
nibble2hex(X) when X < 10 -> $0 + X; % {{{
nibble2hex(X) -> $A + X - 10. % }}}
bin2hexstring(Bin) -> % {{{
lists:flatten(lists:map(
fun(X) ->
tuple_to_list(byte2hex(X))
end,
binary_to_list(Bin))). % }}}
--
Gaspar Chilingarov
System Administrator,
Network security consulting
t +37493 419763 (mob)
i 63174784
e nm@REDACTED
w http://zanazan.am/
More information about the erlang-questions
mailing list