SHL: 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:_SHL}} The _SHL function is used to shift the bits of a numerical value to the left. {{PageSyntax}} :{{Parameter|result}} = _SHL({{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}} is...") |
No edit summary |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 7: | Line 7: | ||
{{ | {{PageParameters}} | ||
* {{Parameter|numericalVariable}} is the variable to shift the bits of and can be of the following types: [[INTEGER]], [[LONG]],[[_INTEGER64]], or [[_BYTE]]. | * {{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]]. | * Integer values can be signed or [[_UNSIGNED]]. | ||
Line 20: | Line 20: | ||
{{PageAvailability}} | |||
* '''Version 1.3 and up'''. | * '''Version 1.3 and up'''. | ||
Line 44: | Line 44: | ||
{{Cl|FOR}} I%% = 0 {{Cl|TO}} 8 | {{Cl|FOR}} I%% = 0 {{Cl|TO}} 8 | ||
{{Cl|PRINT}} {{Cl|_SHL}}(A~%%, I%%) | {{Cl|PRINT}} {{Cl|_SHL}}(A~%%, I%%) | ||
{{Cl|NEXT I%% | {{Cl|FOR...NEXT|NEXT}} I%% | ||
{{CodeEnd}} | {{CodeEnd}} | ||
{{OutputStart}} | {{OutputStart}} | ||
Line 59: | Line 59: | ||
* Note: When directly [[PRINT]]ing to screen, the result is calculated internally using a larger variable type so the left most bit is carried to the next value. | * Note: When directly [[PRINT]]ing to screen, the result is calculated internally using a larger variable type so the left most bit is carried to the next value. | ||
** To avoid this store the result in a variable of the same type before printing. | ** To avoid this store the result in a variable of the same type before printing. | ||
{{PageSeeAlso}} | {{PageSeeAlso}} | ||
* [[_SHR]], [[ | * [[_SHR]], [[_ROL]], [[_ROR]] | ||
* [[_BYTE]], [[_INTEGER64]] | * [[_BYTE]], [[INTEGER]] | ||
* [[LONG]], [[_INTEGER64]] | |||
{{PageNavigation}} | {{PageNavigation}} |
Latest revision as of 01:07, 29 January 2023
The _SHL function is used to shift the bits of a numerical value to the left.
Syntax
- result = _SHL(numericalVariable, numericalValue)
Parameters
- 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.
- numericalValue is the number of places to shift the bits.
- While 0 is a valid value it will have no affect on the variable being shifted.
Description
- Allows for multiplication of a value by 2 faster than normal multiplication (see example 2 below).
- Bits that reach the end of a variable's bit count are dropped (when using a variable of the same type - otherwise they will carry over).
- The type of variable used to store the results should match the type of the variable being shifted.
Availability
- Version 1.3 and up.
Examples
Example 1:
A~%% = 1 'set right most bit of an_UNSIGNED _BYTE PRINT A~%% PRINT _SHL(A~%%,7) B~%% = _SHL(A~%%,8) 'shift the bit off the left 'edge' PRINT B~%% |
1 128 0 |
Example 2:
A~%% = 1 FOR I%% = 0 TO 8 PRINT _SHL(A~%%, I%%) NEXT I%% |
1 2 4 8 16 32 64 128 256 |
- Note: When directly PRINTing to screen, the result is calculated internally using a larger variable type so the left most bit is carried to the next value.
- To avoid this store the result in a variable of the same type before printing.
See also