Create a gist now

Instantly share code, notes, and snippets.

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