Skip to content

Instantly share code, notes, and snippets.

@Sedward
Created June 17, 2010 23:30
Show Gist options
  • Save Sedward/442957 to your computer and use it in GitHub Desktop.
Save Sedward/442957 to your computer and use it in GitHub Desktop.
-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.
@Sedward
Copy link
Author

Sedward commented Jun 17, 2010

encode integers in base36

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment