Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local floor,insert = math.floor, table.insert
- function basen(n,b)
- n = floor(n)
- if not b or b == 10 then return tostring(n) end
- local digits = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
- local t = {}
- local sign = ""
- if n < 0 then
- sign = "-"
- n = -n
- end
- repeat
- local d = (n % b) + 1
- n = floor(n / b)
- insert(t, 1, digits:sub(d,d))
- until n == 0
- return sign .. table.concat(t,"")
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement