Difference between revisions of "Bit32.rshift"
From GiderosMobile
(Created page with "__NOTOC__ '''Available since:''' Gideros 2022.3<br/> '''Class:''' bit32<br/> === Description === Returns a number whose bits have been logically shifted to the right by a...") |
m (Text replacement - "</source>" to "</syntaxhighlight>") |
||
(One intermediate revision by the same user not shown) | |||
Line 5: | Line 5: | ||
=== Description === | === Description === | ||
Returns a number whose bits have been logically shifted to the right by a given displacement. | Returns a number whose bits have been logically shifted to the right by a given displacement. | ||
− | < | + | <syntaxhighlight lang="lua"> |
(number) = bit32.rshift(x,disp) | (number) = bit32.rshift(x,disp) | ||
− | </ | + | </syntaxhighlight> |
Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left. 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 right. The number disp may be any representable integer. Negative displacements shift to the left. 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: | For positive displacements, the following equality holds: | ||
− | < | + | <syntaxhighlight lang="lua"> |
assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp)) | assert(bit32.rshift(b, disp) == math.floor(b % 2^32 / 2^disp)) | ||
− | </ | + | </syntaxhighlight> |
'''This shift operation is what is called logical shift''' | '''This shift operation is what is called logical shift''' |
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 right by a given displacement.
(number) = bit32.rshift(x,disp)
Returns the number x shifted disp bits to the right. The number disp may be any representable integer. Negative displacements shift to the left. 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.rshift(b, disp) == math.floor(b % 2^32 / 2^disp))
This shift operation is what is called logical shift
Parameters
x: (number) value
disp: (number) displacement
Return values
Returns (number) result after bits right shifted
See also