Difference between revisions of "Bit.brshift"
From ComputerCraft Wiki
m (Moved to CAT:APIFunctions) |
m (Changed nonexistent type int to type number.) |
||
(4 intermediate revisions by 2 users not shown) | |||
Line 2: | Line 2: | ||
{{Function | {{Function | ||
|name=bit.brshift | |name=bit.brshift | ||
− | |args= | + | |args={{Type|number}} n, {{Type|number}} bits |
|api=bit | |api=bit | ||
− | |returns= | + | |returns={{Type|number}} the value of <var>n</var> shifted right by <var>bits</var> bits, with the shifted-in bits being equal to the original number’s 31st bit, which is equivalent to ⌊<var>n</var>÷2<sup><var>bits</var></sup>⌋ |
|addon=ComputerCraft | |addon=ComputerCraft | ||
− | |desc=Shifts a number right by a specified number of bits | + | |desc=Shifts a number right arithmetically by a specified number of bits |
|examples= | |examples= | ||
{{Example | {{Example | ||
Line 12: | Line 12: | ||
|code=print(bit.brshift(73, 2)) | |code=print(bit.brshift(73, 2)) | ||
|output=18 | |output=18 | ||
+ | }} | ||
+ | {{Example | ||
+ | |desc=Shift the number 2,147,483,648 (10000000000000000000000000000000) right by 2 bits, yielding 3,758,096,384 (11100000000000000000000000000000) | ||
+ | |code=print(bit.brshift(2147483648, 2)) | ||
+ | |output=3758096384 | ||
}} | }} | ||
}} | }} | ||
[[Category:API_Functions]] | [[Category:API_Functions]] |
Latest revision as of 01:08, 12 July 2013
Function bit.brshift | |
Shifts a number right arithmetically by a specified number of bits | |
Syntax | bit.brshift(number n, number bits) |
Returns | number the value of n shifted right by bits bits, with the shifted-in bits being equal to the original number’s 31st bit, which is equivalent to ⌊n÷2bits⌋ |
Part of | ComputerCraft |
API | bit |
Examples
Example | |
Shift the number 73 (1001001) right by 2 bits, yielding 18 (10010) | |
Code |
print(bit.brshift(73, 2)) |
Output | 18 |