BitLShift: Difference between revisions
Jump to navigation
Jump to search
(Added page for bitLShift) |
m (Minor description tweak) |
||
(2 intermediate revisions by the same user not shown) | |||
Line 11: | Line 11: | ||
===Required arguments=== | ===Required arguments=== | ||
*'''value:''' The value you want to perform the | *'''value:''' The value you want to perform the shift on. | ||
*'''n:''' The amount of positions to | *'''n:''' The amount of positions to shift the value by. | ||
===Returns=== | ===Returns=== | ||
Line 22: | Line 22: | ||
local value = 0xFFFFFFFF -- binary: 1111 1111 1111 1111 1111 1111 1111 1111, decimal: 4.294.967.295 | local value = 0xFFFFFFFF -- binary: 1111 1111 1111 1111 1111 1111 1111 1111, decimal: 4.294.967.295 | ||
local positions = 0x4 -- binary: 0100, decimal: 4 | local positions = 0x4 -- binary: 0100, decimal: 4 | ||
local shifted = bitLShift( value, positions ) -- binary: 1111 1111 1111 1111 1111 1111 1111 0000, decimal: | local shifted = bitLShift( value, positions ) -- binary: 1111 1111 1111 1111 1111 1111 1111 0000, decimal: 4.294.967.280 | ||
-- Comparsion: | |||
-- binary: 1111 1111 1111 1111 1111 1111 1111 1111, decimal: 4.294.967.295 | |||
-- binary: 1111 1111 1111 1111 1111 1111 1111 0000, decimal: 4.294.967.280 | |||
</syntaxhighlight> | </syntaxhighlight> | ||
==See Also== | ==See Also== | ||
{{Bit_functions}} | {{Bit_functions}} |
Latest revision as of 22:29, 21 February 2016
This functions performs a logical left shift on the integer value by integer n positions. In a logical shift, zeros are shifted in to replace the discarded bits. See Bitwise operation for more details.
Syntax
int bitLShift ( int value, int n )
Required arguments
- value: The value you want to perform the shift on.
- n: The amount of positions to shift the value by.
Returns
Returns the logical left shifted value as integer.
Example
This example shows the usage of the function bitLShift.
local value = 0xFFFFFFFF -- binary: 1111 1111 1111 1111 1111 1111 1111 1111, decimal: 4.294.967.295 local positions = 0x4 -- binary: 0100, decimal: 4 local shifted = bitLShift( value, positions ) -- binary: 1111 1111 1111 1111 1111 1111 1111 0000, decimal: 4.294.967.280 -- Comparsion: -- binary: 1111 1111 1111 1111 1111 1111 1111 1111, decimal: 4.294.967.295 -- binary: 1111 1111 1111 1111 1111 1111 1111 0000, decimal: 4.294.967.280