Revision [13374]
This is an old revision of KeyPgOpShiftRight made by CountingPine on 2008-05-15 12:29:26.
Operator Shr (Shift right)
Shifts the bits of a numeric expression to the right
Syntax:
KeyPgDeclare declare KeyPgOperator operator Shr ( KeyPgByref byref lhs KeyPgAs as KeyPgInteger integer, KeyPgByref byref rhs KeyPgAs as KeyPgInteger integer ) KeyPgAs as KeyPgInteger integer
KeyPgDeclare declare KeyPgOperator operator Shr ( KeyPgByref byref lhs KeyPgAs as KeyPgUinteger uinteger, KeyPgByref byref rhs KeyPgAs as KeyPgUinteger uinteger ) KeyPgAs as KeyPgUinteger uinteger
KeyPgDeclare declare KeyPgOperator operator Shr ( KeyPgByref byref lhs KeyPgAs as KeyPgLongint longint, KeyPgByref byref rhs KeyPgAs as KeyPgLongint longint ) KeyPgAs as KeyPgLongint longint
KeyPgDeclare declare KeyPgOperator operator Shr ( KeyPgByref byref lhs KeyPgAs as KeyPgUlongint ulongint, KeyPgByref byref rhs KeyPgAs as KeyPgUlongint ulongint ) KeyPgAs as KeyPgUlongint ulongint
KeyPgDeclare declare KeyPgOperator operator Shr ( KeyPgByref byref lhs KeyPgAs as KeyPgUinteger uinteger, KeyPgByref byref rhs KeyPgAs as KeyPgUinteger uinteger ) KeyPgAs as KeyPgUinteger uinteger
KeyPgDeclare declare KeyPgOperator operator Shr ( KeyPgByref byref lhs KeyPgAs as KeyPgLongint longint, KeyPgByref byref rhs KeyPgAs as KeyPgLongint longint ) KeyPgAs as KeyPgLongint longint
KeyPgDeclare declare KeyPgOperator operator Shr ( KeyPgByref byref lhs KeyPgAs as KeyPgUlongint ulongint, KeyPgByref byref rhs KeyPgAs as KeyPgUlongint ulongint ) KeyPgAs as KeyPgUlongint ulongint
Usage:
result = lhs Shr rhs
Parameters:
lhs
The left-hand side expression.
rhs
The right-hand side shift expression.
Return Value:
Returns the result of lhs being shifted right rhs number of times.
Description:
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). This has the effect of dividing lhs by two for each shift. For example, "&b0101 Shr 1" returns the binary number &b010, and "5 Shr 1" returns 2.
If the left-hand side expression is signed, the sign bit is copied in the newly created bits on the left after the shift.
Neither of the operands are modified in any way.
This operator can be overloaded for user-defined types.
Examples:
'Halve a number
For i As Integer = 0 To 10
Print 1000 Shr i, Bin(1000 Shr i, 16)
Next i
For i As Integer = 0 To 10
Print 1000 Shr i, Bin(1000 Shr i, 16)
Next i
Output:
1000 0000001111101000 500 0000000111110100 250 0000000011111010 125 0000000001111101 62 0000000000111110 31 0000000000011111 15 0000000000001111 7 0000000000000111 3 0000000000000011 1 0000000000000001 0 0000000000000000
Dialect Differences:
- Not available in the CompilerOptlang -lang qb dialect unless referenced with the alias __Shr.
Differences from QB:
- New to FreeBASIC
See also:
- KeyPgOpCombineShiftRight Operator Shr= (Shift Right and Assign)
- KeyPgOpShiftLeft Operator Shl (Shift left)
- KeyPgBin Bin
- CatPgMath Mathematical Functions
Back to Arithmetic Operators
Back to Operators