Section 6.7: Shifts (Frame 7)                     [prev][home][next]

The arithmetic shift seems a bit stranger at first until we realize that the idea is to preserve the sign of 2's complement numbers, which is useful when using shifting to emulate multiplication and division of signed integers. To do an arithmetic shift, remember the original value of the MSB (most significant bit, which is the leftmost bit), then do a logical shift, inserting 0s on the left or right end, depending upon whether the shift is right or left. Then copy the original sign bit into the MSB. Here are some examples using 8-bit words:

Left arithmetic shift  Original value  Right arithmetic shift
-------------------------------------------------------------------
   01011010               00101101            00010110
   11110100               11111010            11111101
   10111010               11011101            11101110
   10111010               10011101            11001110