–turn to binary
function numberToBits(src)
local result = {}
local bitLen = 32
for i = 1, bitLen do
result[i] = src % 2
src = math.floor(src / 2)
end
return result < br>end
Note: Define an array, and then convert the incoming number to binary
–Get the current page A non-zero value of digits
function getBitOrder(src)
local bitLen = 32
local result = 0
for i=1, bitLen do
if src[i]== 1 then
result = i
return result
end
end
return 0
end
Note: This is used as a standard value judgment , Get the serial number of the standard value
function isBitIn(src, haveType)
local _order = getBitOrder(numberToBits(haveType))
local _srcTable = numberToBits(src)
if _srcTable[_order ]==1 then
return true
end
return false
end
Note: Determine whether the src contains the type of haveType , Judge according to the return value
Usage:
if isBitIn(0x00800402, 0x00000400) then
End
Note: Judgment 0x00800402 and 0x00000400 perform bitwise OR operation for judgment
–Turn to 2 hexadecimal
function numberToBits(src)
local result = {}
local bitLen = 32
for i = 1, bitLen do
Result[i] = src % 2
src = math.floor(src / 2)
end
return result
end
注释: 定义一个数组,然后把The incoming number is converted to binary
–Get the current first non-zero value of digits
function getBitOrder(src)
local bitLen = 32
local result = 0
for i=1, bitLen do
if src[i]==1 then
result = i
return result
end
end
return 0
end
Note: This is used to determine the standard value to obtain the serial number of the standard value
function isBitIn(src, haveType)< br> local _order = getBitOrder(numberToBits(haveType))
local _srcTable = numberToBits(src)
if _srcTable[_order]==1 then return true
end
return false
end
Note: Determine whether the src contains the type of haveType, and determine according to the return value
Usage:
if isBitIn(0x0080 0402, 0x00000400) then
end
注释: 判断 0x00800402 跟 0x00000400 进行位或操作,进行判断