Module BitOps
math bit extensions
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)
-- left shift local function lsh(value,shift) return (value*(2^shift)) % 2^24 end -- right shift local function rsh(value,shift) return math.floor(value/2^shift) % 2^24 end
See also:
Functions
- math.bit_or
- Returns the bitwise OR of all arguments.
- math.bit_and
- Returns the bitwise AND of all arguments.
- math.bit_xor
- Returns the bitwise XOR of all arguments.
- math.bit_inv
- Returns the bitwise NOT of the 24 bit integer argument.
- math.bit_bits
- Set each of the bits of a 24 bit integer.
Functions
math.bit_or(a1, a2[, a3[, an]])
Returns the bitwise OR of all arguments.
Only use up to 24 bit integers.
Parameters:
-
a1
number -
a2
number -
a3
number (optional) -
an
number (optional)
Returns:
- number i
math.bit_and(a1, a2[, a3[, an]])
Returns the bitwise AND of all arguments.
Only use up to 24 bit integers.
Parameters:
-
a1
number -
a2
number -
a3
number (optional) -
an
number (optional)
Returns:
- number i
math.bit_xor(a1, a2[, a3[, an]])
Returns the bitwise XOR of all arguments.
Only use up to 24 bit integers.
Parameters:
-
a1
number -
a2
number -
a3
number (optional) -
an
number (optional)
Returns:
- number i
math.bit_inv(a1)
Returns the bitwise NOT of the 24 bit integer argument.
Parameters:
-
a1
number
Returns:
- number i
math.bit_bits(a1, a2[, a3[, an]])
Set each of the bits of a 24 bit integer.
Returns result = result OR (1 << a1) OR (1 << a2) OR ...;)
Parameters:
-
a1
number -
a2
number -
a3
number (optional) -
an
number (optional)
Returns:
- number i