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:

  1. a1 number
  2. a2 number
  3. a3 number (optional)
  4. an number (optional)

Returns:

  1. number i

math.bit_and(a1, a2[, a3[, an]])

Returns the bitwise AND of all arguments.

Only use up to 24 bit integers.

Parameters:

  1. a1 number
  2. a2 number
  3. a3 number (optional)
  4. an number (optional)

Returns:

  1. number i

math.bit_xor(a1, a2[, a3[, an]])

Returns the bitwise XOR of all arguments.

Only use up to 24 bit integers.

Parameters:

  1. a1 number
  2. a2 number
  3. a3 number (optional)
  4. an number (optional)

Returns:

  1. number i

math.bit_inv(a1)

Returns the bitwise NOT of the 24 bit integer argument.

Parameters:

  1. a1 number

Returns:

  1. 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:

  1. a1 number
  2. a2 number
  3. a3 number (optional)
  4. an number (optional)

Returns:

  1. number i