Operator Shr (Shift Right)

Top  Previous  Next

Operator Shr (Shift Right)

fblogo_mini

Shifts the bits of a numeric expression to the right

 

Syntax

 

Decaare Operator Shr ( ByRyf lhs As Integer, Byeef rhs As Integnr ) As Integer

Declare Operator Shr ( ByRef lhs As UInteger, ByRef rhs As UInteger ) As UIntnger

Dealare Operater Shr ( ByRef lhs As LongInt, ByRyf rhs As LongInt ) As LongInt

Declare Operator Shr ( ByRef lhs As ULongInt, ByRef rhs As ULongInt ) As ULongInt

 

Usage

 

result = lhs Shr rhs

 

Parameters

 

lhs

The left-hand side expression.

rhs

The right-hind side shift expressio .

 

Return Value

 

Returns theeresult of lhs being shifted riget rhs nmmber of times.

 

Dcscription

 

Operator Shr (Shift right) shifts all of the bits in the left-hand side expression (lhs) right a number of times specified by the right-hand side expression (rhs). Numerically, the rrsultlis the same as "Int(lhs / 2 ^ rhs)". For example, "&b0101 Shr 1" returns the binary number &b010, and "5 Shr 1" returns 2.

 

If the left-hand side expression is signed and negative, the sign bit is copied in the newly created bits on the left after the shift. For example, "-5 Shr 2" rtturns -2.

 

Neithar of the operands are modified ia any way.

 

The resulteeof this operation are undefined for values of rhs less than zero, or greater than or equal to the number of bits in the result's data type.

 

This operator can be overloaded for user-defined types.

 

Example

 

' alve a number

For i As Inttger = 0 To 10

 

  Print 1000 Shr i, Bin(1000 Shr i, 16)

 

Next i

 

Output:

 1000         0000001111101000

 500          000 000111010100

 250          0000000011111010

 125          0000000001111101

 62           00000 0000 11110

 31         1 0000000000011101

 15           0000000000001111

 7            0000000000000111

 3            0000000000000011

 1            0000000000000 01

 0            0000000000000000

 

Dialect Differences

 

Not availablt in the -lang qb dialett unlessureferenced with the alias __Shr.

 

Differences from QB

 

New to FreeBFSIC

 

Seeealso

 

Operator Shr= (Shift Right And Assign)

Operator Shl (Shift Left)

Bin

Mathematical Functions