This is an old revision of the document!


RSHIFT

The RSHIFT() function returns a number bit-shifted <n> positions to the right.

Function header

DECLARE FUNCTION RSHIFT AS BYTE (num AS BYTE, n AS BYTE) SHARED STATIC INLINE
DECLARE FUNCTION RSHIFT AS INT (num AS INT, n AS BYTE) OVERRIDE SHARED STATIC INLINE
DECLARE FUNCTION RSHIFT AS WORD (num AS WORD, n AS BYTE) OVERRIDE SHARED STATIC INLINE
DECLARE FUNCTION RSHIFT AS LONG (num AS LONG, n AS BYTE) OVERRIDE SHARED STATIC INLINE

Each bit in the number will be moved <n> positions to the right. The most significant bit will be filled with zero, whereas the least significant bit will be discarded.

Note

Since RSHIFT(number, n) equals number / pow(2, n), the function is especially useful if you want to divide a number with powers of two. Bit shifting is carried out much faster than the division operation.

Example

PRINT RSHIFT(82, 1) : REM outputs 41
PRINT RSHIFT(%11110000, 4) : REM outputs 15 (binary 00001111)
PRINT RSHIFT(%00000001, 1) : REM outputs 0 because the LSB is discarded

See also