Bit Library

All bit library functions take 32-bit unsigned integers and return a signed 32-bit result. Take note of this when implementing. If you want unsigned results, we suggest using the bit32 library.

Functions

badd

int bit.badd(...uint)

Adds 2 or more integers.

bsub

int bit.bsub(...uint)

Subtracts 2 or more integers (from left to right).

bmul

int bit.bmul(...uint)

Multiplies 2 or more integers.

bdiv

int bit.bdiv(...uint)

Divides 2 or more integers (from left to right).

band

int bit.band(...uint)

Performs bitwise AND on 2 or more integers.

bor

int bit.bor(...uint)

Performs bitwise OR on 2 or more integers.

bxor

int bit.bxor(...uint)

Performs bitwise XOR on 2 or more integers.

bnot

int bit.bnot(...uint)

Performs bitwise NOT on an integer.

lshift

int bit.lshift(value: uint, n: uint)

Shifts value left by n bits.

rshift

int bit.rshift(value: uint, n: uint)

Shifts value right by n bits.

arshift

int bit.arshift(value: uint, n: uint)

Performs an arthimetic shift right on value by n bits.

rol

int bit.rol(value: uint, n: uint)

Rotates value left n bits.

ror

int bit.ror(value: uint, n: uint)

Rotates value right n bits.

bpopcount

int bit.bpopcount(value: uint)

Returns the number of set bits in value.

bswap

int bit.bswap(value: uint)

Inverts value's endianness.

tohex

int bit.tohex(value: uint, nibbles?: int = 8)

Converts value to a hex string.

tobit

int bit.tobit(value: uint)

Converts value into proper form for bitwise operations.