0

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

Name Name
  • 23
  • 4
  • 2
    17379524724484210731 cannot be represented with signed 64-bit integers. – lhf Aug 21 '21 at 17:29
  • 1
    Is your input a string or a number? – Egor Skriptunoff Aug 24 '21 at 16:53
  • Lua uses double type for numbers (with 56 bit precision) until version 5.2, Lua 5.3 introduced integer type with 64bit precission [https://www.lua.org/manual/5.3/manual.html] Section 2.1. But you are free to recompile lua with custom lua number type. – Darius Aug 26 '21 at 13:44

0 Answers0