Module:DecToHex: Difference between revisions

From Computing Classics Wiki
Hex converter module
 
m 2 revisions imported: All kinds of templates for CCW to emulate AEW's old hard drive stock
 
(One intermediate revision by the same user not shown)
Line 6: Line 6:
hex = hex .. string.format("%x", decToConvert)
hex = hex .. string.format("%x", decToConvert)
if (decToConvert < 16) then
if (string.len(hex) % 2 == 1) then
hex = "0" .. hex
hex = "0" .. hex
end
end

Latest revision as of 06:15, 24 September 2024

Documentation for this module may be created at Module:DecToHex/doc

-- 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.