bitshift
Shift bits specified number of places
Syntax
Description
returns the value of c
= bitshift(a
,k
)fi
object a
with
stored integer value shifted by k
bits.
The shift is arithmetic and behaves like b = a.*2^k
with the value of
b
cast to the type of input a
. The cast of
b
may involve overflow or loss of precision.
The OverflowAction
property of a
is obeyed, but
the RoundingMethod
is always Floor
. If obeying the
RoundingMethod
property of a
is important, try
using the pow2
function.
When the overflow action of a
is Saturate
, the
sign bit is always preserved. When the overflow action of a
is
Wrap
and k
is negative, the sign bit is preserved.
When the overflow action of a
is Wrap
and
k
is positive, the sign bit may change.
When
k
is positive, 0-valued bits are shifted in on the right.When
k
is negative anda
is unsigned, or a signed and positivefi
object, 0-valued bits are shifted in on the left.When
k
is negative anda
is a signed and negativefi
object, 1-valued bits are shifted in on the left.
Examples
Input Arguments
Output Arguments
Extended Capabilities
Version History
Introduced before R2006a