bitshift
Builtin index · Collections & strings
result = bitshift(x, n)
Input: x, n · Output: result
What it is
Shifts an integer's bits left or right. x is a number holding an integer value; n is a number holding an integer shift amount — positive shifts left, negative shifts right (MATLAB's single-function convention rather than separate <</>> operators).
Overloads
One call shape — this function is not overloaded.
| Code | Input | Output | Description |
result = bitshift(x, n) | x numberx is a number holding an integer value.n numbern is a number holding an integer shift amount — positive shifts left, negative shifts right (MATLAB's single-function convention rather than separate <</>> operators). | result number | Returns a number. |
Examples
From the documentation, and run by the build -- the output and the figure below are what the engine actually produced. Simplest first.
flags = bitand(12, 10) # 8 -- bits common to both
print(flags)
print(bitor(12, 10)) # 14
print(bitxor(12, 10)) # 6
print(bitcmp(0)) # -1
print(bitshift(1, 4)) # 16 -- left shift
print(bitshift(16, -2)) # 4 -- right shift
print(xor(true, false)) # true
print(nand(true, true)) # false
print(nor(false, false)) # true
print(hex2dec("FF")) # 255
print(dec2hex(255)) # "FF"
print(bin2dec("1010")) # 10
print(dec2bin(10)) # "1010"
8 14 6 -1 16 4 true false true 255 FF 10 1010
from collections-strings
How it works
bitshift(x, n): positive n shifts left, negative shifts right — MATLAB's own single-function convention, rather than separate <</>> operators.
From the note above this builtin in the interpreter, where the reasoning was written down as it was built.