Bit
These functions provide bitwise operations and manipulations for 32-bit integers.
Note: This bit
library returns signed integers. If you need unsigned output, use the built-in bit32
library instead. Use bit
for signed output and bit32 for unsigned output.
bit.badd(...numbers: number): number
Adds multiple numbers bitwise.
Returns: The bitwise sum of all input numbers.
bit.bsub(...numbers: number): number
Subtracts multiple numbers bitwise, starting from the first number.
Returns: The bitwise subtraction result.
bit.bmul(...numbers: number): number
Multiplies multiple numbers bitwise.
Returns: The bitwise multiplication result.
bit.bdiv(...numbers: number): number
Divides multiple numbers bitwise, starting from the first number.
Returns: The bitwise division result.
bit.band(...numbers: number): number
Performs a bitwise AND operation on all input numbers.
Returns: The result of the bitwise AND operation.
bit.bor(...numbers: number): number
Performs a bitwise OR operation on all input numbers.
Returns: The result of the bitwise OR operation.
bit.bxor(...numbers: number): number
Performs a bitwise XOR operation on all input numbers.
Returns: The result of the bitwise XOR operation.
bit.bnot(number: number): number
Performs a bitwise NOT operation on the input number.
Returns: The result of the bitwise NOT operation.
bit.lshift(value: number, shift: number): number
Performs a left shift operation.
Returns: The result of the left shift operation.
bit.rshift(value: number, shift: number): number
Performs a logical right shift operation.
Returns: The result of the logical right shift operation.
bit.arshift(value: number, shift: number): number
Performs an arithmetic right shift operation.
Returns: The result of the arithmetic right shift operation.
bit.rol(value: number, shift: number): number
Performs a left rotate operation.
Returns: The result of the left rotate operation.
bit.ror(value: number, shift: number): number
Performs a right rotate operation.
Returns: The result of the right rotate operation.
bit.bpopcount(value: number): number
Counts the number of set bits in the input value.
Returns: The number of set bits.
bit.bswap(value: number): number
Swaps the bytes in the input value.
Returns: The value with swapped bytes.
bit.tohex(value: number, [nibbles: number]): string
Converts a number to its hexadecimal representation.
Returns: A string representing the hexadecimal value.
bit.tobit(value: number): number
Converts a number to a 32-bit integer.
Returns: The 32-bit integer representation of the input value.