Announcement

Collapse
No announcement yet.

[Help] Convert base

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • RaMb
    replied
    PHP Code:
    for 2,36 do
        
    local s co('21093974655',i)
        
    local n tonumber(s,i)
        print(
    == 21093974655)
    end 
    Magic number :v :v :v

    Leave a comment:


  • RaMb
    started a topic [Help] Convert base

    [Help] Convert base

    PHP Code:
    local floor,insert math.floortable.insert
    function co(n,b)
        
    floor(n)
        if 
    not b or == 10 then return tostring(nend
        local digits 
    "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
        
    local t = {}
        
    local sign ""
        
    if 0 then
            sign 
    "-"
        
    = -n
        end
        repeat
            local d 
    = (b) + 1
            n 
    floor(b)
            
    insert(t1digits:sub(d,d))
        
    until n == 0
        
    return sign .. table.concat(t,"")
    end 
    That function use to convert a decimal number to other base (36)
    So, this script:
    PHP Code:
    --21093974655
    co
    ('21093974655',36) -- return: 9OUT30F
    tonumber
    ('9OUT30F'36) -- return: 4294967295 
    Whats wrong here @@
    Someone can explain this, thank ._.

    From lua manual:
    tonumber (e [, base])
    Tries to convert its argument to a number. If the argument is already a number or a string convertible to a number, then tonumber returns this number; otherwise, it returns nil.
    An optional argument specifies the base to interpret the numeral. The base may be any integer between 2 and 36, inclusive. In bases above 10, the letter 'A' (in either upper or lower case) represents 10, 'B' represents 11, and so forth, with 'Z' representing 35.
Working...
X