How do I convert string of hex digits to value it represents in Lua

后端 未结 1 1871
醉话见心
醉话见心 2021-02-18 19:49

I\'m reading in a lot of lines of hex data. They come in as strings and I parse them for line_codes which tell me what to do with the rest of the data. One line sets a most sign

相关标签:
1条回答
  • 2021-02-18 20:16

    You use tonumber:

    local someHexString = "03FFACB"
    local someNumber = tonumber(someHexString, 16)
    

    Note that numbers are not in hexadecimal. Nor are they in decimal, octal, or anything else. They're just numbers. The number 0xFF is the same number as 255. "FF" and "255" are string representations of the same number.

    0 讨论(0)
提交回复
热议问题