VOOZH about

URL: https://minecraft.wiki/w/Module:Convert_base

⇱ Module:Convert base – Minecraft Wiki


Module:Convert base

From Minecraft Wiki
Jump to navigation Jump to search
Documentation[view] [edit] [history] [purge]Jump to code ↴

This module allows any number base to be converted to any other number base up to base 15.

It provides 3 convenience functions: fromDec, fromHex, and fromBin, for converting from decimal, hexadecimal, and binary, to any other base; and one main function: fromBase, for everything else.

See also

[view] [edit] [history] [purge]The above documentation is transcluded from Module:Convert base/doc.
localp={}
functionp.fromDec(f)
localargs=f.argsorf
localbase=tonumber(args[2])or16
localdec=tonumber(args[1])or0
ifbase==10ordec==0then
returndec
elseifbase==16then
returnstring.format('%X',dec)
else
localchars='0123456789ABCDEF'
localpos
localout=''
whiledec>0do
pos=math.mod(dec,base)+1
dec=math.floor(dec/base)
out=string.sub(chars,pos,pos)..out
end
returnout
end
end
functionp.fromBase(f)
localargs=f.argsorf
localfromBase=tonumber(args[3])or10
localtoBase=tonumber(args[2])or16
localdec=tonumber(args[1],fromBase)or0
returnp.fromDec{dec,toBase}
end
functionp.fromHex(f)
returnp.fromBase{f.args[1],f.args[2],16}
end
functionp.fromBin(f)
returnp.fromBase{f.args[1],f.args[2],2}
end
returnp
Retrieved from "https://minecraft.wiki/w/Module:Convert_base?oldid=608908"

Navigation menu