# Bit Shift
**An operation which moves, or shifts, the digits of a value left or right.**
The registers of a processor are fixed in width and thus some bits will be *shifted out* at one end while the same amount of bits is *shifted in* at the other.
Bit shift operations are categorised by what value is used for shifted-in bits.
## Logical shift
In a logical shift, bits shifted out are *replaced by zeros* at both ends. It is ideal for unsigned binary numbers.
![[LogicalShift.svg|500]]
## Arithmetic shift
In a *left* arithmetic shift, bits shifted out are replaced by *zeros* on the *right*.
In a *right* arithmetic shift, the value of the *most significant bit* is copied and placed in the vacated bit. A right arithmetic shift preserves the sign of [[Signed Binary Numbers#Signed 2's complement|signed 2's complement numbers]].
A left arithmetic shift is equivalent to a left logical shift.
Arithmetic shifts are commonly used to facilitate the multiplication or division of a number by a power of two. A left or right arithmetic shift by $n$ bits multiplies or divides the number by $2^{n}$ respectively.
![[ArithmeticShift.svg|500]]
## Circular shift
In a circular shift, bits shifted out are preserved in some form.
### Rotate
In a rotate operation, the bits are rotated as if the left and right *ends* of the register are *joined*.
![[RotateShift.svg|400]]
### Rotate through carry
A *rotate through carry* shift, also known as a *rotate with extend* shift, is a variant of the rotate operation where an additional bit supplied by the [[Arithmetic Logic Unit#Status flags|carry flag]].
The bit rotated out becomes the new value of the carry flag.
![[RotateCarryShift.svg|450]]