Created
June 17, 2010 23:30
-
-
Save Sedward/442957 to your computer and use it in GitHub Desktop.
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
-module(base36). | |
-export([encode/1]). | |
encode(Input)-> | |
encode(Input, ""). | |
encode(Input, Encoded) -> | |
if Input > 36 -> | |
E = lookup(Input rem 36), | |
encode(Input div 36,[E|Encoded]); | |
true -> E = lookup(Input), | |
[E|Encoded] | |
end. | |
lookup(Input) -> | |
Charset = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ", | |
lookup(Charset, Input, 0). | |
lookup([H | T], Input, Index) -> | |
if Input == Index -> H; | |
true -> lookup(T, Input, Index + 1) | |
end. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
encode integers in base36