Performs an arithmetic right shift of the specified 32-bit integer by the given number of bits. Bits shifted out of the bottom are discarded and the sign bit is copied into the vacated high-order bits, preserving the sign of the value.
Parameters
Name
Type
Description
x
T
The value to be shifted.
disp
integer
The number of bits to shift right by.
Returns
Type
Name
Description
T
result
The shifted value, normalized to a signed 32-bit integer.
functionraw.bit.extract(x: T, field: integer, width?: integer): T
Extracts a bit field of the given width from the specified 32-bit integer, starting at the given bit position (0-indexed, counted from the least significant bit).
Rotates the bits of the specified 32-bit integer to the left by the given number of bits. Bits shifted out of the top are wrapped around and shifted in at the bottom.
Parameters
Name
Type
Description
x
T
The value to be rotated.
disp
integer
The number of bits to rotate left by.
Returns
Type
Name
Description
T
result
The rotated value, normalized to a signed 32-bit integer.
Performs a logical left shift of the specified 32-bit integer by the given number of bits. Bits shifted out of the top are discarded and zero bits are shifted in from the bottom.
Parameters
Name
Type
Description
x
T
The value to be shifted.
disp
integer
The number of bits to shift left by.
Returns
Type
Name
Description
T
result
The shifted value, normalized to a signed 32-bit integer.
functionraw.bit.replace(x: T, extract: T, field: integer, width?: integer): T
Replaces a bit field of the given width in the specified 32-bit integer, starting at the given bit position (0-indexed, counted from the least significant bit), with the bits taken from extract.
Parameters
Name
Type
Description
x
T
The value whose bit field is to be replaced.
extract
T
The value providing the replacement bits (only the lowest width bits are used).
field
integer
The starting bit position of the field to replace (0-indexed).
widthoptional
integer
The number of bits in the field. Defaults to 1.
Returns
Type
Name
Description
T
result
The value of x with the specified bit field replaced.
functionraw.bit.reverse(x: T, bit_count?: integer): T
Reverses the order of the lowest bit_count bits of x, so the least significant bit becomes the most significant bit (within that range) and vice versa.
Rotates the bits of the specified 32-bit integer to the right by the given number of bits. Bits shifted out of the bottom are wrapped around and shifted in at the top.
Parameters
Name
Type
Description
x
T
The value to be rotated.
disp
integer
The number of bits to rotate right by.
Returns
Type
Name
Description
T
result
The rotated value, normalized to a signed 32-bit integer.
Performs a logical right shift of the specified 32-bit integer by the given number of bits. Bits shifted out of the bottom are discarded and zero bits are shifted in from the top, regardless of the sign of the value.
Parameters
Name
Type
Description
x
T
The value to be shifted.
disp
integer
The number of bits to shift right by.
Returns
Type
Name
Description
T
result
The shifted value, normalized to a signed 32-bit integer.
functionraw.bit.sign(x: T, bit_count?: integer): T
Converts an unsigned bit_count-bit integer to its signed (two's complement) value, the inverse of rbit.unsign.
Every positive x has 2 ^ bit_count subtracted from it, so only pass values that have the sign bit set; zero and negative values are returned unchanged.