Notice that if we treat the bit strings as unsigned integers, then left logical shifts seem to perform multiplication, while right logical shifts perform division. For example, 00010111 is 23, and 00101110, the result of a left logical 1-bit shift, is 46. If we shift 00010111 two bits and get 01011100, the value is 92, or 23x4. Thus, the number of shifts is the power of 2 by which the unsigned number is multiplied. However, if 1s are lost off the left end, the result will be less than the original number, which signifies yet another form of overflow. In all cases, overflow is a result of not having enough bits to store a value, and it always occurs in this world of finite machines. Right logical shifts are divisions by 2, but it is integer division with truncation. For example, 23/2 is 11.5, or just 11 if we truncate, and indeed 00001011 is 11. Right logical shifts can never result in overflow because the new number resulting from the shift or division is always smaller than the original. But information is lost nonetheless because decimal places are eroded away until the result is 0. |