Module:DecToHex

From Australian Enthusiasts Wiki
Revision as of 08:06, 4 March 2021 by TheDragonFire123 (talk | contribs) (Update to always zero-pad odd digit hexes)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

This Lua module converts a decimal input into a lowercase hex output.

To return a uppercase hex value, you must wrap the value in string.upper().


-- Convert given decimals to lowercase hex.
local p = {}

function p.decToHex(decToConvert)
	hex = ""
	hex = hex .. string.format("%x", decToConvert)
	
	if (string.len(hex) % 2 == 1) then
		hex = "0" .. hex
	end
	
	return hex
end

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