Note: This page has been translated by MathWorks. Click here to see

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

To view all translated materials including this page, select Country from the country navigator on the bottom of this page.

Shift bits specified number of places

`intout = bitshift(A,k)`

`intout = bitshift(A,k,assumedtype)`

returns `intout`

= bitshift(`A`

,`k`

)`A`

shifted
to the left by `k`

bits, equivalent to multiplying
by 2

. Negative values
of ^{k}`k`

correspond to shifting bits right or dividing
by 2

and rounding
to the nearest integer towards negative infinity. Any overflow bits
are truncated. ^{|k|}

If

`A`

is an array of signed integers, then`bitshift`

returns the arithmetic shift results, preserving the signed bit when`k`

is negative, and not preserving the signed bit when`k`

is positive.If

`k`

is positive, MATLAB^{®}shifts the bits to the left and inserts`k`

0-bits on the right.If

`k`

is negative and`A`

is nonnegative, then MATLAB shifts the bits to the right and inserts`|`

`k`

`|`

0-bits on the left.If

`k`

is negative and`A`

is negative, then MATLAB shifts the bits to the right and inserts`|`

`k`

`|`

1-bits on the left.

assumes `intout`

= bitshift(`A`

,`k`

,`assumedtype`

)`A`

is
of type `assumedtype`

.

Was this topic helpful?