RShift Function
Shifts numeric data to the right by a user specified number of bits.
Syntax
RShift(number, shiftBits)
Parameters
- number
- Specify the numeric value to be logically shifted, either as an expression or directly as a numeric value.
- shiftBits
- Specifies the bit numeric value (integer value from 0 to 31) to be right-logically shifted.
Return Values
Returns a numeric result which is equal to the value of number after shifting right shiftbits number of bits.
Description
RShift shifts the specified numeric data (number) to the right (toward a lower order digit) by the specified number of bits (shiftBits). The high order bits shifted are replaced by 0.
The simplest explanation for RShift is that it simply returns the result of number / 2shiftBits. (Number is divided by 2 shiftBit times.)
Note
Numeric Data Type:
The numeric data (number) may be any valid numeric data type.
RShift supports the following data types:
Byte, Double, Int32, Integer, Long, Real, Short, UByte, UInt32, and UShort.
See Also
And, LShift, LShift64, Not, Or, RShift64, Xor
RShift Function Example
The example shown below shows a program which shows all the possible RShift values for an Integer data type starting with the integer set to “0”.
Function rshiftst
Integer num, snum, i
num = 32767
For i = 1 to 16
Print "i =", i
snum = RShift(num, 1)
Print "RShift(32767, ", i, ") = ", snum
Next i
Fend
Some other example results from the RShift instruction from the command window.
> Print RShift(10,1)
5
> Print RShift(8,3)
1
> Print RShift(16,2)
4