ยินดีต้อนรับเข้าสู่ Minecraft Wiki แห่งใหม่! อ่านประกาศที่นี่
ข่าวสาร Minecraft WIki
แนะนำ “เครื่องคำนวณ” โปรแกรมช่วยคำนวณสิ่งต่าง ๆ ใน Minecraft
อัปเดตกฎระเบียบของวิกิ | แนวปฏิบัติหน้าพูดคุย | อัปเดตแนวปฏิบัติในการเขียน
อัปเดตกฎระเบียบของวิกิ | แนวปฏิบัติหน้าพูดคุย | อัปเดตแนวปฏิบัติในการเขียน
|
มอดูล:Convert base
ไปยังการนำทาง
ไปยังการค้นหา
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[แก้ไขต้นฉบับ]
{{Decimal to binary converter}}
{{Decimal to hexadecimal converter}}
{{Hexadecimal to decimal converter}}
[ดู] [แก้ไข] [ประวัติ] [ล้างแคช]คู่มือการใช้งานที่ปรากฏด้านบนนี้ดึงมาจาก มอดูล:Convert base/doc
local p = {}
function p.fromDec( f )
local args = f.args or f
local base = tonumber( args[2] ) or 16
local dec = tonumber( args[1] ) or 0
if base == 10 or dec == 0 then
return dec
elseif base == 16 then
return string.format( '%X', dec )
else
local chars = '0123456789ABCDEF'
local pos
local out = ''
while dec > 0 do
pos = math.mod( dec, base ) + 1
dec = math.floor( dec / base )
out = string.sub( chars, pos, pos ) .. out
end
return out
end
end
function p.fromBase( f )
local args = f.args or f
local fromBase = tonumber( args[3] ) or 10
local toBase = tonumber( args[2] ) or 16
local dec = tonumber( args[1], fromBase ) or 0
return p.fromDec{ dec, toBase }
end
function p.fromHex( f )
return p.fromBase{ f.args[1], f.args[2], 16 }
end
function p.fromBin( f )
return p.fromBase{ f.args[1], f.args[2], 2 }
end
return p