This preview shows page 1. Sign up to view the full content.
Unformatted text preview: eight Two’s Complement Original Truncated
¼ ¼ ¿ ¼ ¿ ½ ¾ ½ As Equation 2.7 states, the effect of this truncation on unsigned values is to simply to ﬁnd their residue, modulo 8. The effect of the truncation on signed values is a bit more complex. According to Equation 2.8, we ﬁrst compute the modulo 8 residue of the argument. This will give values ¼– for arguments ¼– , and also for arguments – ½. Then we apply function Í¾Ì ¿ to these residues, giving two repetitions of the sequences ¼–¿ and – ½. Problem 2.16 Solution: [Pg. 52] This problem was designed to demonstrate how easily bugs can arise due to the implicit casting from signed to unsigned. It seems quite natural to pass parameter length as an unsigned, since one would never want to use a negative length. The stopping criterion i <= length-1 also seems quite natural. But combining these two yields an unexpected outcome! Since parameter length is unsigned, the computation ¼ ½ is performed using unsigned arithmetic, which is equivalent to modular addition. The result is then ÍÅ Ü ¿¾ (assuming a 32-bit machine). The co...
View Full Document