Lua BitOps
From Spring
Development < Lua Scripting < Lua BitOps
Bit Operators
math.bit_and
( int a1 [, int a2 [, ... ] ] ) -> int i
math.bit_or
( int a1 [, int a2 [, ... ] ] ) -> int i
math.bit_xor
( int a1 [, int a2 [, ... ] ] ) -> int i
math.bit_inv
( int a1 ) -> int i
math.bit_bits (result = result | (1 << a1) | (1 << a2) | ...;)
( int a1 [, int a2 [, ... ] ] ) -> int i
-- Note: there are no bit shift. Use those Lua functions instead for 24 bits bitshift -- 24 bits because only the 24 bits of the mantissa can be easily used in a 32 bit float -- bitshift functions (<<, >> equivalent)
-- shift left
local function lsh(value,shift)
return (value*(2^shift)) % 2^24
end
-- shift right
local function rsh(value,shift)
return math.floor(value/2^shift) % 2^24
end