bit32

bit32 is the provided library for doing bit shifting, logic, arithmatic, etc.

Second Life's version is slightly modified in that if the arguments you pass are all integer types then the result will also be an integer.

Structure

Functions

Name Description
arshift Shifts n by i bits to the right (if i is negative, a left shift is performed instead).
The most significant bit of n is propagated during the shift.
When i is larger than 31, returns an integer with all bits set to the sign bit of n.
When i is smaller than -31, 0 is returned
band Performs a bitwise and of all input numbers and returns the result.
If the function is called with no arguments, an integer with all bits set to 1 is returned.
bnot Returns a bitwise negation of the input number.
bor Performs a bitwise or of all input numbers and returns the result.
If the function is called with no arguments, 0 is returned.
btest Perform a bitwise and of all input numbers, and return true if the result is not 0.
If the function is called with no arguments, true is returned.
bxor Performs a bitwise xor (exclusive or) of all input numbers and returns the result.
If the function is called with no arguments, 0 is returned.
byteswap Returns n with the order of the bytes swapped.
countlz Returns the number of consecutive zero bits in the 32-bit representation of n starting from the left-most (most significant) bit.
Returns 32 if n is 0.
countrz Returns the number of consecutive zero bits in the 32-bit representation of n starting from the right-most (least significant) bit.
Returns 32 if n is 0.
extract Extracts bits of n at position f with a width of w, and returns the resulting integer.
w defaults to 1, so a two-argument version of extract returns the bit value at position f.
Bits are indexed starting at 0.
Errors if f and f+w-1 are not between 0 and 31.
lrotate Rotates n to the left by i bits (if i is negative, a right rotate is performed instead)
The bits that are shifted past the bit width are shifted back from the right.
lshift Shifts n to the left by i bits (if i is negative, a right shift is performed instead).
When i is outside of [-31..31] range, returns 0.
replace Replaces bits of n at position f and width w with r, and returns the resulting integer.
w defaults to 1, so a three-argument version of replace changes one bit at position f to r (which should be 0 or 1) and returns the result.
Bits are indexed starting at 0.
Errors if f and f+w-1 are not between 0 and 31.
rrotate Rotates n to the right by i bits (if i is negative, a left rotate is performed instead)
The bits that are shifted past the bit width are shifted back from the left.
rshift Shifts n to the right by i bits (if i is negative, a left shift is performed instead).
When i is outside of [-31..31] range, returns 0.

< Back to SLua