Retro Rocket OS
BASIC-Powered Operating System
Loading...
Searching...
No Matches
SHR Function
SHR(value, count)

Performs a bitwise shift right operation on an integer. The first parameter is the value to shift, the second is the number of bit positions.


Examples

PRINT SHR(4, 1)

Produces 2 (01000010).

PRINT SHR(9, 2)

Produces 2 (10010010, fractional part discarded).

REM Divide by powers of two using SHR
n = 40
PRINT SHR(n, 3) ' Same as 40 / 8 = 5

Notes

  • Operates on 64-bit integers.
  • Shifting right by n positions is equivalent to integer division by 2^n.
  • Bits shifted out on the right are discarded; new bits on the left are filled with zero.
  • This is a logical shift (fills with zero), not an arithmetic shift. Negative values are not sign-extended.
  • If the shift count is negative or larger than the bit width, behaviour is undefined.

See also: SHL · BITAND · BITOR · BITNAND