Difference between revisions of "Bit32.lshift"
From GiderosMobile
m (Text replacement - "<source" to "<syntaxhighlight") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
Line 7: | Line 7: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
(number) = bit32.lshift(x,disp) | (number) = bit32.lshift(x,disp) | ||
− | </ | + | </syntaxhighlight> |
Returns the number x shifted disp bits to the left. The number disp may be any representable integer. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out). | Returns the number x shifted disp bits to the left. The number disp may be any representable integer. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out). | ||
Line 14: | Line 14: | ||
<syntaxhighlight lang="lua"> | <syntaxhighlight lang="lua"> | ||
assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32) | assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32) | ||
− | </ | + | </syntaxhighlight> |
=== Parameters === | === Parameters === |
Latest revision as of 14:27, 13 July 2023
Available since: Gideros 2022.3
Class: bit32
Description
Returns a number whose bits have been logically shifted to the left by a given displacement.
(number) = bit32.lshift(x,disp)
Returns the number x shifted disp bits to the left. The number disp may be any representable integer. Negative displacements shift to the right. In any direction, vacant bits are filled with zeros. In particular, displacements with absolute values higher than 31 result in zero (all bits are shifted out).
For positive displacements, the following equality holds:
assert(bit32.lshift(b, disp) == (b * 2^disp) % 2^32)
Parameters
x: (number) value
disp: (number) displacement
Return values
Returns (number) result after bits left shifted
See also