_SHR

From QB64.org wiki
Jump to navigation Jump to search

The _SHR function is used to shift the bits of a numerical value to the right.


Syntax

Template:Parameter = _SHR(Template:Parameter, Template:Parameter)


Parameters


Description

  • Allows for division of a value by 2 faster than normal division (see example 2 below).
  • Bits that reach the end of a variables bit count are dropped.
  • The type of variable used to store the results should match the type of the variable being shifted.
  • NOTE: When dealing with SIGNED variables, shifting the bits right will leave the sign bit set. This is due to how C++ deals with bit shifting under the hood.

Availability

  • Version 1.3 and up.


Examples

Example 1:

A~%% = 128 'set left most bit of anTemplate:Cl Template:Cl Template:Cl A~%% Template:Cl Template:Cl(A~%%,7) Template:Cl Template:Cl(A~%%,8) 'shift the bit off the right 'edge'

Template:OutputStart

128
1
0

Template:OutputEnd


Example 2:

A~%% = 128 Template:Cl I%% = 0 Template:Cl 8 Template:Cl Template:Cl(A~%%, I%%) Template:Cl

Template:OutputStart

128
 64
 32
 16
 8
 4
 2
 1
 0

Template:OutputEnd

See also



Navigation:
Go to Keyword Reference - Alphabetical
Go to Keyword Reference - By usage
Go to Main WIKI Page