This preview shows page 1. Sign up to view the full content.
Unformatted text preview: , for unsigned variable Û x, the C expression x << k is equivalent to x * pwr2k, where pwr2k equals ¾k . In particular, we can compute pwr2k as 1U << k. By similar reasoning, we can show that for a two’s complement number Ü having bit pattern ÜÛ ½ ÜÛ ¾ and any in the range ¼ Û, bit pattern ÜÛ ½ Ü¼ ¼ ¼ will be the two’s complement representation of Ü *tÛ ¾ . Therefore, for signed variable x , the C expression x << k is equivalent to x * pwr2k, where pwr2k equals ¾k . Note that multiplying by a power of two can cause overﬂow with either unsigned or two’s complement arithmetic. Our result shows that even then we will get the same effect by shifting. Practice Problem 2.21:
As we will see in Chapter 3, the leal instruction on an Intel-compatible processor can perform computations of the form a<<k + b, where k is either 0, 1, or 2, and b is either 0 or some program value. The compiler often uses this instruction to perform multiplications by constant factors. For example, we can compute 3...
View Full Document
- Spring '10
- The American