Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
v3:rshift [2021/10/13 10:59] – [Function header] neilsv3:rshift [2021/10/14 08:51] (current) – removed neils
Line 1: Line 1:
-====== 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. 
- 
-<adm note> 
-Since ''RSHIFT(number, n)'' equals ''number / pow(2, n)'', the function is especially useful if you want to divide a number by powers of two. Bit shifting is carried out much faster than the division operation. 
-</adm> 
- 
-===== 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 ===== 
- 
-  * [[LSHIFT]] 
-