lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Norbert Kiesel wrote:
[snip]
function tohex(decimal)
   if type(decimal) == 'number' or #decimal < 15 then
      return ('%x'):format(decimal)
   end
   local hex = ''
   while decimal do
      local div = ''
      local mod = 0
      for i = 1, #decimal do
mod = mod * 10 + tonumber(decimal:sub(i, i))
local f = math.floor(mod / 16)
mod = mod - f * 16
div = div .. f end
      hex = ('%x'):format(mod) .. hex
      decimal = div:match('0+(.+)')
   end

   return hex
end

Oh sorry, ha ha, I failed to see the nested loop. ;-)

It looks real slow... :-)

--
Cheers,
Kein-Hong Man (esq.)
Kuala Lumpur, Malaysia