--[[
Description:
FileName:bit.lua
This module provides a selection of bitwise operations.
History:
Initial version created by 阵雨 2005-11-10.
Notes:
....
]]
--[[{2147483648,1073741824,536870912,268435456,134217728,67108864,33554432,16777216,
8388608,4194304,2097152,1048576,524288,262144,131072,65536,
32768,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,1}
]]
bit={data32={}}
for i=1,32 do
bit.data32[i]=2^(32-i)
end
function bit:d2b(arg)
local tr={}
for i=1,32 do
if arg >= self.data32[i] then
tr[i]=1
arg=arg-self.data32[i]
else
tr[i]=0
end
end
return tr
end --bit:d2b
function bit:b2d(arg)
local nr=0
for i=1,32 do
if arg[i] ==1 then
nr=nr+2^(32-i)
end
end
return nr
end --bit:b2d
function bit:_xor(a,b)
local op1&
lua中位运算操作
最新推荐文章于 2022-11-20 15:55:46 发布
本文详细介绍了 Lua 语言中的位运算操作,包括按位与、按位或、按位异或、按位非、左移和右移等基本操作,并通过实例解析其用法和应用场景。
摘要由CSDN通过智能技术生成