ROR: Difference between revisions
Jump to navigation
Jump to search
Navigation:
Main Page with Articles and Tutorials
Keyword Reference - Alphabetical
Keyword Reference - By usage
Report a broken link
(Created page with "{{DISPLAYTITLE:_ROR}} 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}} t...") |
(Initial version) |
||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_ROR}} | {{DISPLAYTITLE:_ROR}} | ||
The [[ | The [[_ROR]] function is used to shift the bits of a numerical value to the right. A rotation (or circular shift) is an operation similar to shift ([[_SHL]] and [[_SHR]]) except that the bits that fall off at one end are put back to the other end. | ||
{{PageSyntax}} | {{PageSyntax}} | ||
:{{Parameter|result}} = [[ | :{{Parameter|result}} = [[_ROR]]({{Parameter|numericalVariable}}, {{Parameter|numericalValue}}) | ||
{{Parameters}} | {{Parameters}} | ||
* {{Parameter|numericalVariable}} is the variable to shift the bits of and can be of the following types: [[ | * {{Parameter|numericalVariable}} is the variable to shift the bits of and can be of the following types: [[_BYTE]], [[INTEGER]], [[LONG]], or [[_INTEGER64]]. | ||
* Integer values can be signed or [[_UNSIGNED]]. | * Integer values can be signed or [[_UNSIGNED]]. | ||
* {{Parameter|numericalValue}} the number of places to | * {{Parameter|numericalValue}} is the number of places to rotate the bits. | ||
* While 0 is a valid value it will have no affect on the variable being | * While 0 is a valid value it will have no affect on the variable being rotated. | ||
{{PageDescription}} | {{PageDescription}} | ||
* | * In right rotation, the bits that fall off at right end are put back at left end. | ||
* The type of variable used to store the results should match the type of the variable being shifted. | * The type of variable used to store the results should match the type of the variable being shifted. | ||
==Availability== | ==Availability== | ||
* '''Version 1. | * '''Version 3.1.0 and up'''. | ||
{{PageExamples}} | {{PageExamples}} | ||
{{CodeStart}} | |||
{{ | {{Cl|OPTION _EXPLICIT}} | ||
{{Cl| | |||
{{Cl| | {{Cl|DIM}} a {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|_BYTE}} | ||
{{Cl| | {{Cl|DIM}} b {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|INTEGER}} | ||
{{ | {{Cl|DIM}} c {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|LONG}} | ||
{{ | {{Cl|DIM}} d {{Cl|AS}} {{Cl|_UNSIGNED}} {{Cl|_INTEGER64}} | ||
a = &B11110000 | |||
b = &B1111111100000000 | |||
{{ | c = &B11111111111111110000000000000000 | ||
d = &B1111111111111111111111111111111100000000000000000000000000000000 | |||
{{Cl|DO}} | |||
a = {{Cl|_ROR}}(a, 1) | |||
b = {{Cl|_ROR}}(b, 1) | |||
c = {{Cl|_ROR}}(c, 1) | |||
d = {{Cl|_ROR}}(d, 1) | |||
{{Cl|LOCATE}} 1, 1: {{Cl|PRINT}} {{Cl|RIGHT$}}({{Cl|STRING$}}(8, "0") + {{Cl|_BIN$}}(a), 8); | |||
{{Cl|LOCATE}} 2, 1: {{Cl|PRINT}} {{Cl|RIGHT$}}({{Cl|STRING$}}(16, "0") + {{Cl|_BIN$}}(b), 16); | |||
{{Cl|LOCATE}} 3, 1: {{Cl|PRINT}} {{Cl|RIGHT$}}({{Cl|STRING$}}(32, "0") + {{Cl|_BIN$}}(c), 32); | |||
{{Cl|LOCATE}} 4, 1: {{Cl|PRINT}} {{Cl|RIGHT$}}({{Cl|STRING$}}(64, "0") + {{Cl|_BIN$}}(d), 64); | |||
{{Cl|_LIMIT}} 15 | |||
{{Cl|LOOP}} {{Cl|WHILE}} {{Cl|_KEYHIT}} <> 27 | |||
{{Cl| | |||
{{Cl| | |||
{{CodeEnd}} | {{CodeEnd}} | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[_SHL]], [[ | * [[_ROL]], [[_SHL]], [[_SHR]] | ||
* [[ | * [[_BYTE]], [[INTEGER]] | ||
* [[LONG]], [[_INTEGER64]] | |||
{{PageNavigation}} | {{PageNavigation}} |
Revision as of 20:55, 3 September 2022
The _ROR function is used to shift the bits of a numerical value to the right. A rotation (or circular shift) is an operation similar to shift (_SHL and _SHR) except that the bits that fall off at one end are put back to the other end.
Syntax
- result = _ROR(numericalVariable, numericalValue)
- numericalVariable is the variable to shift the bits of and can be of the following types: _BYTE, INTEGER, LONG, or _INTEGER64.
- Integer values can be signed or _UNSIGNED.
- numericalValue is the number of places to rotate the bits.
- While 0 is a valid value it will have no affect on the variable being rotated.
Description
- In right rotation, the bits that fall off at right end are put back at left end.
- The type of variable used to store the results should match the type of the variable being shifted.
Availability
- Version 3.1.0 and up.
Examples
OPTION _EXPLICIT DIM a AS _UNSIGNED _BYTE DIM b AS _UNSIGNED INTEGER DIM c AS _UNSIGNED LONG DIM d AS _UNSIGNED _INTEGER64 a = &B11110000 b = &B1111111100000000 c = &B11111111111111110000000000000000 d = &B1111111111111111111111111111111100000000000000000000000000000000 DO a = _ROR(a, 1) b = _ROR(b, 1) c = _ROR(c, 1) d = _ROR(d, 1) LOCATE 1, 1: PRINT RIGHT$(STRING$(8, "0") + _BIN$(a), 8); LOCATE 2, 1: PRINT RIGHT$(STRING$(16, "0") + _BIN$(b), 16); LOCATE 3, 1: PRINT RIGHT$(STRING$(32, "0") + _BIN$(c), 32); LOCATE 4, 1: PRINT RIGHT$(STRING$(64, "0") + _BIN$(d), 64); _LIMIT 15 LOOP WHILE _KEYHIT <> 27 |
See also