uint64 to hex in lua 5.1

486 Views Asked by At

Hey I am not able to make this conversion correctly. I use below code

RawGUID=17379524724484210731 --It's impossible to store variable this way, it will always convert into test3 eventually. Stored as userdata I cannot change
test1="17379524724484210731"

test2="1.7379524724484e+019"
test3=1.7379524724484e+019

function tohex(num)
    local charset = {"0","1","2","3","4","5","6","7","8","9","A","B","C","D","E","F"}
    local tmp = {}
    repeat
        table.insert(tmp,1,charset[num%16+1])
        num = math.floor(num/16)
    until num==0
    return table.concat(tmp)
end

RawGUID is an example of what I need to convert into hex string, the rest of the variables is just conversion of the same number. The code works well for anything that's below 64bits.

To be honest, to achieve my goal I need a string in hex to make the rest of my code work

The result I am getting: F13079A800000000

The result I want: F13079A80000002B

0

There are 0 best solutions below