Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何在lua中将32字节字符缓冲区转换为uint64?_Lua_Char_Buffer_Uint64 - Fatal编程技术网

如何在lua中将32字节字符缓冲区转换为uint64?

如何在lua中将32字节字符缓冲区转换为uint64?,lua,char,buffer,uint64,Lua,Char,Buffer,Uint64,我正在编写一种机制来生成从sha256派生的唯一ID。我使用: require 'sha2' function getUint64ID( callId ) local minimumValue = 100000000000000000 local maximumValue = 999999999999999999 outputHash = sha2.sha256hex(callId) print(outputHash .. "\n") local c1 = ""

我正在编写一种机制来生成从sha256派生的唯一ID。我使用:

require 'sha2'

function getUint64ID( callId )
  local minimumValue = 100000000000000000
  local maximumValue = 999999999999999999

  outputHash = sha2.sha256hex(callId)
  print(outputHash .. "\n")

  local c1 = ""

  for a, b in outputHash:gmatch"(%x)(%x)" do
    hexTuple = tostring(a) .. tostring(b)
    intVal   = tonumber(hexTuple, 16)
    c1 = c1 .. string.char(intVal)
  end

  uint64ID = ( minimumValue + ( tonumber(c1) % ( maximumValue - minimumValue + 1 ) ) )

  print('uint64ID:')
  print(string.format("%18.0f",uint64ID))
end

getUint64ID("test")
我在上面的代码中得到以下错误:

stdin:17: attempt to perform arithmetic on a nil value
stack traceback:
    stdin:17: in function 'getUint64ID'
    stdin:1: in main chunk
    [C]: ?

如何在lua中将32字节字符缓冲区(c1)转换为uint64数字?

如何只执行
uint64ID=minimumValue+tonumber(输出:sub(1,14),16)
tonumber(c1)
nil
,因为
c1
包含任意符号(而不是十进制数字)