Repository navigation
Operator Shr Shift Right
Home › Operators › Operator Shr (Shift Right)
Shifts the bits of a numeric expression to the right
Declare Operator Shr ( ByRef lhs As Integer, ByRef rhs As Integer ) As Integer
Declare Operator Shr ( ByRef lhs As UInteger, ByRef rhs As UInteger ) As UInteger
Declare Operator Shr ( ByRef lhs As LongInt, ByRef rhs As LongInt ) As LongInt
Declare Operator Shr ( ByRef lhs As ULongInt, ByRef rhs As ULongInt ) As ULongIntlhsrhs
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 result is 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" returns -2.
Neither of the operands are modified in any way.
The results of 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.
Returns the result of lhs being shifted right rhs number of times.
result = lhs Shr rhs
- Not available in the -lang qb dialect unless referenced with the alias
__Shr.
- New to FreeBASIC
'Halve a number
For i As Integer = 0 To 10
Print 1000 Shr i, Bin(1000 Shr i, 16)
Next iOutput:
1000 0000001111101000
500 0000000111110100
250 0000000011111010
125 0000000001111101
62 0000000000111110
31 0000000000011111
15 0000000000001111
7 0000000000000111
3 0000000000000011
1 0000000000000001
0 0000000000000000Category: Operators
Kind: operator
Reproduced from the FreeBASIC Wiki Manual under the GNU Free Documentation License 1.3 — with no Invariant Sections, no Front-Cover Texts and no Back-Cover Texts. Copyright © the FreeBASIC project and wiki contributors. See License.
tiko-lang · Home · Feature Index · Keyword Index · License
FreeBASIC manual pages reproduced under the GNU FDL 1.3.
- Generics
- Interfaces
- For Each
- Iterators
- Tuples
- Array Results
- Defer
- Lambdas
- Block Strings
- Partial Types
- String Slices
- Embed
- Typed Variadics
- C Header Import
- Foreign Library Linking
- UString
- Fixed-Width Types
- Nullptr
- String Library
- Format
- Array
- Map
- Set
- LinkedList
- OrderedMap
- OrderedSet
- Sorting
- Optional
- Result
- Smart Pointers
- Date and Time (Chrono)
- Filesystem
- File Streams
- Config (INI and TOML)
- Codec
- Hash
- UUID
- OS
- Process
- Net
- HTTP and TLS
- Math Library
- Finance
- Logging
- Terminal TUI Library
- PsControls
- tkControls
- sys/win
- Goroutines and Channels
- LLVM Backend
- tiko build
- TIKO_COMPILER
- Variable Declarations
- Standard Data Types
- User Defined Types
- Procedures
- Operators
- Control Flow Statements
- Converting Data Types
- Array Functions
- String Functions
- Mathematical Functions
- Bit Manipulation
- Date and Time Functions
- File I/O Functions
- Console Functions
- User Input (Runtime Library)
- User Input Functions (Graphics Library)
- Screen Functions
- 2D Drawing Functions
- Graphics Library Reference
- Graphics Keyword List
- Memory Functions
- Threading Support Functions
- Error Handling Functions
- Operating System Functions
- Preprocessor
- Intrinsic Defines
- Miscellaneous Keywords
- Modularizing