05.08.2020, 12:52
@Erwin, you example splits 32 bits into two 16 bit values. Lua bit operations work only with 32 bit numbers. FFI can be used to convert between different types:
Code:
function u64_to_u32(value)
local ffi = require('ffi')
local u64 = ffi.new('uint64_t[1]', value)
local u32 = ffi.new('uint32_t[2]')
ffi.copy(u32, u64, 8)
return u32[0], u32[1]
end
value = math.pow(2, 53) - 1 -- some large value
u32_l, u32_h = u64_to_u32(value)
log(u32_l, u32_h)