Arithmetic Shifts

Understanding Arithmetic Shifts

  • Arithmetic Shifts are operations used to manipulate binary numbers by shifting their bits either to the right or the left.
  • These types of shifts fill the space vacated depending on the type of shift and considering the sign bit as well.

Arithmetic Right Shifts

  • An arithmetic right shift pulls all bits one place to the right.
  • The leftmost bit (most significant bit) retains its previous value. This bit is often known as the sign bit, because it’s used to represent whether a number is positive or negative in signed number representations.
  • The rightmost bit is discarded.
  • For example, if we arithmetically right-shift the binary number 1101 (which is 13 in decimal or -3 in two’s complement form), we get 1110 (which is -2 in two’s complement form).

Arithmetic Left Shifts

  • An arithmetic left shift effectively multiplies the binary number by 2, shifting all bits in the binary number one place to the left.
  • The rightmost bit will become 0, and the original leftmost bit is discarded.
  • For instance, if we arithmetically left-shift the binary number 1011 (which is 11 in decimal or -5 in two’s complement form), we would get 0110 (which is 6 in decimal).

Practical Use of Arithmetic Shifts

  • Similar to logical shifts, arithmetic shifts are useful for multiplication or division by two. An arithmetic shift left doubles the original number, while an arithmetic shift right halves it.
  • Unlike logical shifts, arithmetic shifts consider the sign of the number. This makes them especially useful in multiplication and division operations for signed binary numbers.

Important Considerations for Arithmetic Shifts

  • The crucial difference to remember when comparing arithmetic and logical shifts is that arithmetic shifts take into account the sign of a number.
  • As they keep track of whether a number is negative or positive, they are the better choice when dealing with signed binary numbers.
  • However, wrongly using these operation while ignoring the sign bit condition can lead to inaccurate results. It’s therefore vitally important to understand their function and proper use.