Skip to content

Instantly share code, notes, and snippets.

@reverendpaco
Created April 27, 2014 22:11
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 reverendpaco/e07f6311e1b34bac70da to your computer and use it in GitHub Desktop.
Save reverendpaco/e07f6311e1b34bac70da to your computer and use it in GitHub Desktop.
Simple Number-Encoder using Crockford-32
encodeCrockford(Num) ->
encode(Num,32,fun crockford32e/1).
encode(Num,Radix,Fun) ->
Indices = make_number(Num,Radix,[]),
lists:map(fun(X) ->
Fun(X) end, Indices).
make_number(Num,Radix,Accum) ->
Remainder = Num rem Radix,
Div = Num div Radix,
Accum2 = [Remainder | Accum],
case {Div,Remainder} of
{0,0} ->
Accum;
_ ->
make_number(Div,Radix,Accum2)
end.
crockford32e(X) ->
element(X+1,
{
$0, $1, $2, $3, $4, $5, $6, $7, $8, $9, $A, $B, $C, $D, $E, $F, $G, $H, $J, $K, $M, $N,
$P, $Q, $R, $S, $T, $V, $W, $X, $Y, $Z}).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment