Jump to content

Non-decimal radices/Convert: Difference between revisions

Lua: fix case of n = 0
(support 0, fix non-exhaustive matching, use modern API)
(Lua: fix case of n = 0)
Line 2,252:
Only had to write 'dec2base' as the reverse is provided by the in-built function 'tonumber'
<syntaxhighlight lang="lua">function dec2base (base, n)
local result, digit = ""
while n > 0 dorepeat
local digit = n % base
if digit > 9 then digit = string.char(digit + 87) end
n digit = mathstring.floorchar(ndigit /+ base87)
end
result = digit .. result
n = n // base
end
until n == 0
return result
end
559

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.