-
-
Save reverendpaco/e07f6311e1b34bac70da to your computer and use it in GitHub Desktop.
Simple Number-Encoder using Crockford-32
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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