<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="vi">
	<id>https://bktt.vn/index.php?action=history&amp;feed=atom&amp;title=M%C3%B4_%C4%91un%3ABaseConvert</id>
	<title>Mô đun:BaseConvert - Lịch sử thay đổi</title>
	<link rel="self" type="application/atom+xml" href="https://bktt.vn/index.php?action=history&amp;feed=atom&amp;title=M%C3%B4_%C4%91un%3ABaseConvert"/>
	<link rel="alternate" type="text/html" href="https://bktt.vn/index.php?title=M%C3%B4_%C4%91un:BaseConvert&amp;action=history"/>
	<updated>2026-04-04T08:43:18Z</updated>
	<subtitle>Lịch sử thay đổi của trang này ở wiki</subtitle>
	<generator>MediaWiki 1.35.0</generator>
	<entry>
		<id>https://bktt.vn/index.php?title=M%C3%B4_%C4%91un:BaseConvert&amp;diff=5975&amp;oldid=prev</id>
		<title>Taitamtinh: Tạo trang mới với nội dung “local p = {}  local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'  function normalizeFullWidthChars(s)     return mw.ustring.gsub(s, '[！-～]', functi…”</title>
		<link rel="alternate" type="text/html" href="https://bktt.vn/index.php?title=M%C3%B4_%C4%91un:BaseConvert&amp;diff=5975&amp;oldid=prev"/>
		<updated>2020-10-30T15:33:17Z</updated>

		<summary type="html">&lt;p&gt;Tạo trang mới với nội dung “local p = {}  local digits = &amp;#039;0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ&amp;#039;  function normalizeFullWidthChars(s)     return mw.ustring.gsub(s, &amp;#039;[！-～]&amp;#039;, functi…”&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Trang mới&lt;/b&gt;&lt;/p&gt;&lt;div&gt;local p = {}&lt;br /&gt;
&lt;br /&gt;
local digits = '0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ'&lt;br /&gt;
&lt;br /&gt;
function normalizeFullWidthChars(s)&lt;br /&gt;
    return mw.ustring.gsub(s, '[！-～]', function(s) &lt;br /&gt;
        return mw.ustring.char(mw.ustring.codepoint(s, 1) - 0xFEE0) &lt;br /&gt;
    end)    &lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function _convert(n, base, from, precision, width, default, prefix, suffix)&lt;br /&gt;
    n = '' .. n   -- convert to a string&lt;br /&gt;
    &lt;br /&gt;
    -- strip off any leading '0x' (unless x is a valid digit in the input base)&lt;br /&gt;
    from = tonumber(from)&lt;br /&gt;
    if not from or from &amp;lt; 34 then&lt;br /&gt;
        local c&lt;br /&gt;
        n, c = n:gsub('^(-?)0[Xx]', '%1')&lt;br /&gt;
        if c &amp;gt; 0 and not from then from = 16 end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    -- check for a negative sign. Do this while the input is still in string form,&lt;br /&gt;
    -- because tonumber doesn't support negative numbers in non-10 bases.&lt;br /&gt;
    local sign = ''&lt;br /&gt;
    local c&lt;br /&gt;
    n, c = n:gsub('^-', '')&lt;br /&gt;
    if c &amp;gt; 0 then sign = '-' end&lt;br /&gt;
    &lt;br /&gt;
    -- replace any full-width Unicode characters in the string with their ASCII equivalents&lt;br /&gt;
    n = normalizeFullWidthChars(n)&lt;br /&gt;
    &lt;br /&gt;
    -- handle scientific notation with whitespace around the 'e' e.g. '5 e7'&lt;br /&gt;
    n = n:gsub('%s*[eE]%s*', 'e')&lt;br /&gt;
    &lt;br /&gt;
    from = from or 10&lt;br /&gt;
    local num = tonumber(n, from)&lt;br /&gt;
    base = tonumber(base)&lt;br /&gt;
    precision = tonumber(precision)&lt;br /&gt;
    width = tonumber(width)&lt;br /&gt;
    &lt;br /&gt;
    if not num or not base then return default or n end&lt;br /&gt;
    &lt;br /&gt;
    local i, f = math.modf(num)&lt;br /&gt;
&lt;br /&gt;
    local t = {}&lt;br /&gt;
    repeat&lt;br /&gt;
        local d = (i % base) + 1&lt;br /&gt;
        i = math.floor(i / base)&lt;br /&gt;
        table.insert(t, 1, digits:sub(d, d))&lt;br /&gt;
    until i == 0&lt;br /&gt;
    while #t &amp;lt; (width or 0) do&lt;br /&gt;
        table.insert(t, 1, '0') &lt;br /&gt;
    end&lt;br /&gt;
    local intPart = table.concat(t, '')&lt;br /&gt;
    &lt;br /&gt;
    -- compute the fractional part&lt;br /&gt;
    local tf = {}&lt;br /&gt;
    while f &amp;gt; 0 and #tf &amp;lt; (precision or 10) do&lt;br /&gt;
        f = f * base&lt;br /&gt;
        i, f = math.modf(f)&lt;br /&gt;
        table.insert(tf, digits:sub(i + 1, i + 1))&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- add trailing zeros if needed&lt;br /&gt;
    if precision and #tf &amp;lt; precision then&lt;br /&gt;
        for i = 1, precision - #tf do&lt;br /&gt;
            table.insert(tf, '0') &lt;br /&gt;
        end&lt;br /&gt;
    end&lt;br /&gt;
&lt;br /&gt;
    fracPart = table.concat(tf, '')&lt;br /&gt;
    &lt;br /&gt;
    -- remove trailing zeros if not needed&lt;br /&gt;
    if not precision then&lt;br /&gt;
        fracPart = fracPart:gsub('0*$', '')&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    -- add the radix point if needed&lt;br /&gt;
    if #fracPart &amp;gt; 0 then&lt;br /&gt;
        fracPart = '.' .. fracPart&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    return (prefix or '') .. sign .. intPart .. fracPart .. (suffix or '')&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
function p.convert(frame)&lt;br /&gt;
    -- Allow for invocation via #gọi or directly from another module&lt;br /&gt;
    local args&lt;br /&gt;
    if frame == mw.getCurrentFrame() then&lt;br /&gt;
        args = frame.args&lt;br /&gt;
    else&lt;br /&gt;
        args = frame&lt;br /&gt;
    end&lt;br /&gt;
    &lt;br /&gt;
    local n = args.n&lt;br /&gt;
    local base = args.base&lt;br /&gt;
    local from = args.from&lt;br /&gt;
    local precision = args.precision&lt;br /&gt;
    local width = args.width&lt;br /&gt;
    local default = args.default&lt;br /&gt;
    local prefix = args.prefix&lt;br /&gt;
    local suffix = args.suffix&lt;br /&gt;
    return _convert(n, base, from, precision, width, default, prefix, suffix)&lt;br /&gt;
end&lt;br /&gt;
&lt;br /&gt;
return p&lt;/div&gt;</summary>
		<author><name>Taitamtinh</name></author>
	</entry>
</feed>