mirror of
https://github.com/QB64Official/qb64.git
synced 2024-09-13 09:23:54 +00:00
65 lines
1.5 KiB
Text
65 lines
1.5 KiB
Text
|
{{DISPLAYTITLE:_SHR}}
|
||
|
The [[_SHR]] function is used to shift the bits of a numerical value to the right.
|
||
|
|
||
|
|
||
|
{{PageSyntax}}
|
||
|
:{{Parameter|result}} = [[_SHR]]({{Parameter|numericalVariable}}, {{Parameter|numericalValue}})
|
||
|
|
||
|
|
||
|
{{Parameters}}
|
||
|
* {{Parameter|numericalVariable}} is the variable to shift the bits of and can be of the following types: [[INTEGER]], [[LONG]], [[_INTEGER64]], or [[_BYTE]].
|
||
|
* Integer values can be signed or [[_UNSIGNED]].
|
||
|
* {{Parameter|numericalValue}} the number of places to shift the bits.
|
||
|
* While 0 is a valid value it will have no affect on the variable being shifted.
|
||
|
|
||
|
|
||
|
{{PageDescription}}
|
||
|
* 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.
|
||
|
|
||
|
|
||
|
==Availability==
|
||
|
* '''Version 1.3 and up'''.
|
||
|
|
||
|
|
||
|
{{PageExamples}}
|
||
|
''Example 1:''
|
||
|
{{CodeStart}}A~%% = 128 'set left most bit of an{{Cl|_UNSIGNED}} {{Cl|_BYTE}}
|
||
|
{{Cl|PRINT}} A~%%
|
||
|
{{Cl|PRINT}} {{Cl|_SHR}}(A~%%,7)
|
||
|
{{Cl|PRINT}} {{Cl|_SHR}}(A~%%,8) 'shift the bit off the right 'edge'
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStart}}
|
||
|
128
|
||
|
1
|
||
|
0
|
||
|
{{OutputEnd}}
|
||
|
|
||
|
|
||
|
''Example 2:''
|
||
|
{{CodeStart}}
|
||
|
A~%% = 128
|
||
|
{{Cl|FOR}} I%% = 0 {{Cl|TO}} 8
|
||
|
{{Cl|PRINT}} {{Cl|_SHR}}(A~%%, I%%)
|
||
|
{{Cl|NEXT I%%}}
|
||
|
{{CodeEnd}}
|
||
|
{{OutputStart}}
|
||
|
128
|
||
|
64
|
||
|
32
|
||
|
16
|
||
|
8
|
||
|
4
|
||
|
2
|
||
|
1
|
||
|
0
|
||
|
{{OutputEnd}}
|
||
|
|
||
|
{{PageSeeAlso}}
|
||
|
* [[_SHL]], [[INTEGER]], [[LONG]]
|
||
|
* [[_BYTE]], [[_INTEGER64]]
|
||
|
|
||
|
|
||
|
{{PageNavigation}}
|