bitshift
Shift bits specified number of places
Description
returnsintout
= bitshift(A
,k
)A
shifted to the left byk
bits, equivalent to multiplying by 2k
. Negative values ofk
correspond to shifting bits right or dividing by 2|k|
and rounding to the nearest integer towards negative infinity. Any overflow bits are truncated.
If
A
is an array of signed integers, thenbitshift
returns the arithmetic shift results, preserving the signed bit whenk
is negative, and not preserving the signed bit whenk
is positive.If
k
is positive, MATLAB®shifts the bits to the left and insertsk
0-bits on the right.If
k
is negative andA
is nonnegative, then MATLAB shifts the bits to the right and inserts|
k
|
0-bits on the left.If
k
is negative andA
is negative, then MATLAB shifts the bits to the right and inserts|
k
|
1-bits on the left.
assumesintout
= bitshift(A
,k
,assumedtype
)A
is of typeassumedtype
.