Reply To: re-usable modulators ?

Home Forums General Programming re-usable modulators ? Reply To: re-usable modulators ?

#82751
goodweather
Participant
  • Topics: 45
  • Replies: 550
  • Total: 595
  • ★★★

Good! And I forgot to say that with Lua you can also have tables in tables if I’m not wrong…

hex2dec and dec2hex is easy:

--
-- Returns HEX representation of a DECimal number
--
dec2hex = function(num)

    local hexstr = '0123456789ABCDEF'
    local s = ''

    while num > 0 do
        local mod = math.fmod(num, 16)
        s = string.sub(hexstr, mod+1, mod+1) .. s
        num = math.floor(num / 16)
    end
    if s == '' then s = '0' end
    return s

end

--
-- 	For the conversion of a DECimal number to anything else
--	it is just needed to use the built-in Lua function tonumber(string, base)
--
--	print(tonumber("0100",2))
--	4
-- 	print(tonumber("3F",16))
-- 	63
Ctrlr