This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

LUA : An easy way to separate an int64 into two int32 ?
#7
@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)
Reply


Messages In This Thread
RE: LUA : An easy way to separate an int64 into two int32 ? - by admin - 05.08.2020, 12:52

Forum Jump: