Library bit
LuaJIT's bit library. All inputs and results are expressed as signed 32-bit integers.
Functions
| arshift( value, amount ) | Returns the arithmetic right-shift of the given value. |
| band( ... ) | Returns the bitwise-and of the given values. |
| bnot( value ) | Returns the the given value with every bit flipped. |
| bor( ... ) | Returns the bitwise-or of the given values. |
| bswap( value ) | Returns the given argument with its byte order swapped. |
| bxor( ... ) | Returns the bitwise-xor of the given values. |
| lshift( value, amount ) | Returns the logical left shift of the given value. |
| rol( value, amount ) | Returns the bitwise left rotation of the given value. |
| ror( value, amount ) | Returns the bitwise right rotation of the given value. |
| rshift( value, amount ) | Returns the logical right shift of the given value. |
| tobit( value ) | Returns the given value normalised into the numeric range used in bitwise operations (i.e. 32-bit signed integer range). |
| tohex( value, numDigits ) | Returns the hexadecimal representation of the given value. |
Functions
- bit.arshift( value, amount )
-
Returns the arithmetic right-shift of the given value.
Environment:
SharedParameters:
-
(number) value: The value to shift. -
(number) amount: The amount to shift by (between 0 and 31).
-
- bit.band( ... )
-
Returns the bitwise-and of the given values.
Environment:
SharedParameters:
-
(number...) ...: The values to combine using the bitwise-and operator.
-
- bit.bnot( value )
-
Returns the the given value with every bit flipped.
Environment:
SharedParameters:
-
(number) value: The value to apply the bitwise-not operator to.
-
- bit.bor( ... )
-
Returns the bitwise-or of the given values.
Environment:
SharedParameters:
-
(number...) ...: The values to combine using the bitwise-or operator.
-
- bit.bswap( value )
-
Returns the given argument with its byte order swapped. This can be used to convert from big-endian to little-endian and vice-versa.
Environment:
SharedParameters:
-
(number) value: The value to swap the bytes of.
-
- bit.bxor( ... )
-
Returns the bitwise-xor of the given values.
Environment:
SharedParameters:
-
(number...) ...: The values to combine using the bitwise-xor operator.
-
- bit.lshift( value, amount )
-
Returns the logical left shift of the given value.
Environment:
SharedParameters:
-
(number) value: The value to shift. -
(number) amount: The amount to shift by (between 0 and 31).
-
- bit.rol( value, amount )
-
Returns the bitwise left rotation of the given value. Unlike shifts, rotations insert bits that are shifted out of one side back into the other side.
Environment:
SharedParameters:
-
(number) value: The value to rotate. -
(number) amount: The amount to rotate by (between 0 and 31).
-
- bit.ror( value, amount )
-
Returns the bitwise right rotation of the given value. Unlike shifts, rotations insert bits that are shifted out of one side back into the other side.
Environment:
SharedParameters:
-
(number) value: The value to rotate. -
(number) amount: The amount to rotate by (between 0 and 31).
-
- bit.rshift( value, amount )
-
Returns the logical right shift of the given value.
Environment:
SharedParameters:
-
(number) value: The value to shift. -
(number) amount: The amount to shift by (between 0 and 31).
-
- bit.tobit( value )
-
Returns the given value normalised into the numeric range used in bitwise operations (i.e. 32-bit signed integer range). Note that all bitwise operations normalise their inputs automatically, so this is usually unnecessary.
Environment:
SharedParameters:
-
(number) value: The value to normalise.
-
- bit.tohex( value, numDigits )
-
Returns the hexadecimal representation of the given value.
Environment:
SharedParameters:
-
(number) value: The value to represent as a hexadecimal string. -
(number?) numDigits: The number of hexadecimal digits to return in the given string (default = 8). Negative values upper-case the output.
-