Anonymous user
Non-decimal radices/Convert: Difference between revisions
Added Lua version
(Wrong code added--non functional) |
(Added Lua version) |
||
Line 1,381:
26
</pre>
=={{header|Lua}}==
Only had to write 'dec2base' as the reverse is provided by the in-built function 'tonumber'
<lang Lua>function dec2base (base, n)
local result, digit = ""
while n > 0 do
digit = n % base
if digit > 9 then digit = string.char(digit + 87) end
n = math.floor(n / base)
result = digit .. result
end
return result
end
local x = dec2base(16, 26)
print(x) --> 1a
print(tonumber(x, 16)) --> 26</lang>
=={{header|Mathematica}}==
|