ROL: 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
No edit summary |
No edit summary |
||
(2 intermediate revisions by the same user not shown) | |||
Line 1: | Line 1: | ||
{{DISPLAYTITLE:_ROL}} | {{DISPLAYTITLE:_ROL}} | ||
The [[_ROL]] function is used to rotate the bits of a numerical value to the left. 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. | The [[_ROL]] function is used to rotate the bits of a numerical value to the left. 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. | ||
Line 7: | Line 7: | ||
{{ | {{PageParameters}} | ||
* {{Parameter|numericalVariable}} is the variable to shift the bits of and can be of the following types: [[_BYTE]], [[INTEGER]], [[LONG]], or [[_INTEGER64]]. | * {{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]]. | ||
Line 20: | Line 20: | ||
{{PageAvailability}} | {{PageAvailability}} | ||
* '''QB64-PE v3.1 and up''' | * '''QB64-PE v3.1.0 and up''' | ||
Latest revision as of 02:18, 24 January 2023
The _ROL function is used to rotate the bits of a numerical value to the left. 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 = _ROL(numericalVariable, numericalValue)
Parameters
- 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 left rotation, the bits that fall off at left end are put back at right end.
- The type of variable used to store the results should match the type of the variable being shifted.
Availability
- QB64-PE v3.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 = _ROL(a, 1) b = _ROL(b, 1) c = _ROL(c, 1) d = _ROL(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