1
1
Fork 0
mirror of https://github.com/QB64-Phoenix-Edition/QB64pe.git synced 2024-06-29 11:40:38 +00:00
QB64-PE/internal/help/_SHL.txt
SteveMcNeill 33adc04fc4 Add temp folder to repo. It's necessary as well!
Just more initial setting on... nothing much to see here.
2022-04-28 13:39:56 -04:00

69 lines
1.8 KiB
Plaintext

{{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 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 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'''.
{{PageExamples}}
''Example 1:''
{{CodeStart}}A~%% = 1 'set right most bit of an{{Cl|_UNSIGNED}} {{Cl|_BYTE}}
{{Cl|PRINT}} A~%%
{{Cl|PRINT}} {{Cl|_SHL}}(A~%%,7)
B~%% = {{Cl|_SHL}}(A~%%,8) 'shift the bit off the left 'edge'
{{Cl|PRINT}} B~%%
{{CodeEnd}}
{{OutputStart}}
1
128
0
{{OutputEnd}}
''Example 2:''
{{CodeStart}}
A~%% = 1
{{Cl|FOR}} I%% = 0 {{Cl|TO}} 8
{{Cl|PRINT}} {{Cl|_SHL}}(A~%%, I%%)
{{Cl|FOR...NEXT|NEXT}} I%%
{{CodeEnd}}
{{OutputStart}}
1
2
4
8
16
32
64
128
256
{{OutputEnd}}
* 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.
{{PageSeeAlso}}
* [[_SHR]], [[INTEGER]], [[LONG]]
* [[_BYTE]], [[_INTEGER64]]
{{PageNavigation}}
<