本文介绍了bit32.band类似的64位操作的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Lua 5.1的64位中应用按位AND运算.是否有算法? (我不知道该怎么做.)

I want to apply a bitwise AND operation in 64 bits in Lua 5.1. Is there an algorithm for it? (I have no idea on how to do it.)

注意:我总共只需要对48位进行操作,就可以使用它们了.

Note: I only need to operate on 48 bits at total, and I am not having trouble with them.

在游戏的Lua中,我正在编写脚本,其中只有bit32库.

In the game's Lua I'm scripting there's the bit32 library only.

推荐答案

local function band48 (x, y)
   local xl = x % 4294967296
   local yl = y % 4294967296
   local xh = (x - xl) / 4294967296
   local yh = (y - yl) / 4294967296
   return bit32.band(xh, yh) * 4294967296 + bit32.band(xl, yl)
end

print(band48(7 * 2^33 + 3, 5*2^33 + 5)) --> 5*2^33+1 = 42949672961

这篇关于bit32.band类似的64位操作的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-14 05:08