Skip to content

Instantly share code, notes, and snippets.

@LennyPenny
Created May 24, 2014 12:16
Show Gist options
  • Save LennyPenny/7d2d5fb76de5ae1e5c8e to your computer and use it in GitHub Desktop.
Save LennyPenny/7d2d5fb76de5ae1e5c8e to your computer and use it in GitHub Desktop.
lua base6xxx
local function baseEnc(n, b)
n = math.floor(n)
if not b or b == 10 then return tostring(n) end
local digits = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789"
local t = {}
local sign = ""
if n < 0 then
sign = "-"
n = -n
end
repeat
local d = (n % b) + 1
n = math.floor(n / b)
table.insert(t, 1, digits:sub(d, d))
until n == 0
return sign..table.concat(t, "")
end
print(baseEnc(100000000, 62))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment