Computer Composition and Design Homework 5
3.20
[5] <§3.5> What decimal number does the bit pattern 0×0C000000 represent if it is a two’s complement integer? An unsigned integer?
- 首位为0,如果是int类型那么说明是正号,
计算过程为
C(12)×166=201,326,592C(12)\times 16^6 = 201,326,592C(12)×166=201,326,592 - unsigned int的计算同上
3.22
[10] <§3.5> What decimal number does the bit pattern 0×0C000000 represent if it is a floating point number? Use the IEEE 754 standard
表示为2进制为
0 (符号位)00011000 (指数位)0000000000 0000000000 000(小数部分)0\ (符号位) 00011000\ (指数位)0000000000\ 0000000000\ 000(小数部分)0 (符号位)00011000 (指数位)0000000000 0000000000 000(小数部分)
不难发现这个数是正数,且偏移量为24 - 127 = -103
所以该数为 1.0×2−1031.0\times 2^{-103}1.0×2−103
3.23
[10] <§3.5> Write down the binary representation of the decimal number
63.25 assuming the IEEE 754 single precision format
63.25二进制表示为
111111.01=1.1111101×25111111.01 = 1.1111101\times 2^{5}111111.01=1.1111101×25
127+5 = 132 = 10000100(2)
于是表示如下
0100001001111101000 0000000000 0000\quad 10000100\quad 1111101000\ 0000000000\ 0000100001001111101000 0000000000 000
3.24
[10] <§3.5> Write down the binary representation of the decimal number
63.25 assuming the IEEE 754 double precision format.
1023+5 = 1028 = 10000000100(2)
0100000001001111101000 0000000000 0000000000 0000000000 0000000000 000\quad 10000000100\quad 1111101000\ 0000000000\ 0000000000\ 0000000000\ 0000000000\ 000100000001001111101000 0000000000 0000000000 0000000000 0000000000 00
3.25
[10] <§3.5> Write down the binary representation of the decimal number
63.25 assuming it was stored using the single precision IBM format (base 16,
instead of base 2, with 7 bits of exponent).
63.25=111111.01(2)=3F.40(16)=0.3F40×16263.25 = 111111.01(2) = 3F.40(16) = 0.3F40\times16^263.25=111111.01(2)=3F.40(16)=0.3F40×162
标志位为0,指数位为64+2=1000001(2)64+2 = 1000001(2)64+2=1000001(2)
0 10000011111101000 0000000000 0000\quad\ 1000001\quad 1111101000\ 0000000000\ 0000 10000011111101000 0000000000 000
看答案貌似写指数位是64+2 这个IBM偏移量固定为64
3.26
[20] <§3.5> Write down the binary bit pattern to represent −1.5625×10−1-1.5625 \times 10^{-1}−1.5625×10−1assuming a format similar to that employed by the DEC PDP-8 (the left most 12 bits are the exponent stored as a two’s complement number, and the rightmost 24 bits are the fraction stored as a two’s complement number). No hidden 1 is used. Comment on how the range and accuracy of this 36-bit pattern compares to the single and double precision IEEE 754 standards.
−1.5625×10−1=−0.15625=−0.00101(2)=−0.101×2−2-1.5625 \times 10^{-1} = -0.15625 = -0.00101(2) = -0.101\times2^{-2}−1.5625×10−1=−0.15625=−0.00101(2)=−0.101×2−2
所以指数2用补码表示为000000000010,−2为1111111111102用补码表示为000000000010,-2为1111111111102用补码表示为000000000010,−2为111111111110
总的表示为
111111111110(12位)101000000000000000000000(24位)111111111110(12位)\quad101000000000\quad000000000000(24位)111111111110(12位)101000000000000000000000(24位)
- 指数可以表达的数字为−2048∼2047-2048\sim2047−2048∼2047
- 底数可表达2−24∼1−2−242^{-24}\sim 1-2^{-24}2−24∼1−2−24
| DEC PDP-8 | 单精度 | 双精度 | |
| 最小正数 | 2−24×2−20482^{-24}\times2^{-2048}2−24×2−2048 | 1×2−1261\times2^{-126}1×2−126 | 1×2−10221\times2^{-1022}1×2−1022 |
| 最大正数 | (1−2−24)×22047(1-2^{-24})\times2^{2047}(1−2−24)×22047 | (1+1−223)×2127(1+1-2^{23})\times2^{127}(1+1−223)×2127 | (1+1−252)×21023(1+1-2^{52})\times2^{1023}(1+1−252)×21023 |
应该为DEC PDP-8能表示的范围更大
3.27
[20] <§3.5> IEEE 754-2008 contains a half precision that is only 16 bits
wide. Th e left most bit is still the sign bit, the exponent is 5 bits wide and has a bias
of 15, and the mantissa is 10 bits long. A hidden 1 is assumed. Write down the
bit pattern to represent −1.5625×10−1-1.5625 \times 10^{-1}−1.5625×10−1
assuming a version of this format, which
uses an excess-16 format to store the exponent. Comment on how the range and
accuracy of this 16-bit fl oating point format compares to the single precision IEEE
754 standard.
−1.5625×10−1=−0.15625=−0.00101(2)=−1.01×2−3-1.5625 \times 10^{-1} = -0.15625 = -0.00101(2) = -1.01\times2^{-3}−1.5625×10−1=−0.15625=−0.00101(2)=−1.01×2−3
- 符号位为1表示负数
- 指数可表达的部分为1-30,偏移量为15,所以指数用12(01100)表示-3
- 底数部分以0100 0000 00
10110001000000001\quad 01100\quad 01000000001011000100000000
3.29
[20] <§3.5> Calculate the sum of 2.6125×1012.6125\times 10^12.6125×101and 4.150390625×10−14.150390625\times 10^{-1}4.150390625×10−1by hand, assuming A and B are stored in the 16-bit half precision described in Exercise 3.27. Assume 1 guard, 1 round bit, and 1 sticky bit, and round to the nearest even. Show all the steps.
2.6125×101=26.125=1.1010001×242.6125 \times 10^1=26.125 = 1.1010001\times 2^42.6125×101=26.125=1.1010001×24
4.150390625×10−1=1.1010100111×2−24.150390625\times 10^{-1} = 1.1010100111\times 2^{-2}4.150390625×10−1=1.1010100111×2−2
向左移动6位以对齐指数
于是有(注意半精度只有11位用于保存)
1.1010001000
1.0000011010100111 /需要注意开头是1,剩下的部分需要舍去
1.1010100010
额外的位(有6位)超过有效位(11)位的一半,应该是进位
最后
1.1010100011(进位)×24=26.5468751.1010100011(进位)\times 2^4 = 26.5468751.1010100011(进位)×24=26.546875
3.32
[20] <§3.9> Calculate (3.984375×10−1+3.4375×10−1)+1.771×103(3.984375 \times 10^{-1} + 3.4375\times 10^{-1})+ 1.771 \times 10^3(3.984375×10−1+3.4375×10−1)+1.771×103by hand, assuming each of the values are stored in the 16-bit half precision format described in Exercise 3.27 (and also described in the text). Assume 1 guard, 1 round bit, and 1 sticky bit, and round to the nearest even. Show all the steps, and write your answer in both the 16-bit fl oating point format and in decimal.
保留位(Guard bit)、近似位(Round bit)和粘滞位(Sticky bit)。
保留位:近似后的最低位
近似位:保留位的后一位
粘滞位:近似位后的所有位进行或运算后视作一位
3.984375×10−1=1.1001100000×2−23.984375 \times 10^{-1} = 1.1001100000\times 2^{-2}3.984375×10−1=1.1001100000×2−2
3.4375×10−1=1.0110000000×2−23.4375\times 10^{-1} =1.0110000000\times 2^{-2}3.4375×10−1=1.0110000000×2−2
1.771×103=1.1011101011×2101.771 \times 10^3 = 1.1011101011\times 2^{10}1.771×103=1.1011101011×210
| (A) | 1.1001100000 | ×2−2\times 2^{-2}×2−2 |
| (B)+ | 1.0110000000 | ×2−2\times 2^{-2}×2−2 |
| = | 10.1111100000 | ×2−2\times 2^{-2}×2−2 |
| = | 1.0111110000 | ×2−1\times 2^{-1}×2−1 |
| (A+B) | 1.0111110000 | ×2−1\times 2^{-1}×2−1 |
| = | 0.000000000010111110000 | ×210\times 2^{10}×210 |
| C | 1.1011101011 | ×210\times 2^{10}×210(A+B多余的部分是101,超过0.5,应进位) |
| (A+B)+C= | 1.1011101100 | ×210\times 2^{10}×210 |
| = | 1772 |
3.33
[20] <§3.9> Calculate 3.984375×10−1+(3.4375×10−1+1.771×103)3.984375 \times 10^{-1} + (3.4375 \times 10^{-1} + 1.771 \times 10^3)3.984375×10−1+(3.4375×10−1+1.771×103)by hand, assuming each of the values are stored in the 16-bit half precision format described in Exercise 3.27 (and also described in the text). Assume 1 guard, 1 round bit, and 1 sticky bit, and round to the nearest even. Show all the steps, and write your answer in both the 16-bit fl oating point format and in decimal.
3.984375×10−1=1.1001100000×2−23.984375 \times 10^{-1} = 1.1001100000\times 2^{-2}3.984375×10−1=1.1001100000×2−2
3.4375×10−1=1.0110000000×2−23.4375\times 10^{-1} =1.0110000000\times 2^{-2}3.4375×10−1=1.0110000000×2−2
1.771×103=1.1011101011×2101.771 \times 10^3 = 1.1011101011\times 2^{10}1.771×103=1.1011101011×210
| (B) | 0.0000000000010110000000 | ×210\times 2^{10}×210 |
| ©+ | 1.1011101011 | ×210\times 2^{10}×210 |
| = | 1.1011101011 | ×210\times 2^{10}×210 |
| (A) | 0.0000000000011001100000 | ×210\times 2^{10}×210 |
| ©+ | 1.1011101011 | ×210\times 2^{10}×210 |
| = | 1.1011101011 | ×210\times 2^{10}×210 |
| = | 1771 |
3.34
[10] <§3.9> Based on your answers to 3.32 and 3.33, does (3.984375×10−1+3.4375×10−1)+1.771×103=3.984375×10−1+(3.4375×10−1+1.771×103)(3.984375 \times 10^{-1} + 3.4375 \times 10^{-1}) + 1.771 \times 10^3 = 3.984375 \times 10^{-1} + (3.4375\times 10^{-1} + 1.771 \times10^3)(3.984375×10−1+3.4375×10−1)+1.771×103=3.984375×10−1+(3.4375×10−1+1.771×103)?
并不相同,第一个为1772
第二个是1771
精确的解应该为1771.742187
这篇内容涉及浮点数的二进制表示,包括IEEE754标准下的单精度和双精度格式,以及IBM的单精度格式。文章详细解释了如何将十进制数转换为二进制浮点数,并展示了不同格式下表示特定数值的二进制模式。此外,还讨论了DECPDP-8、半精度浮点数格式以及手动计算浮点数加法的过程,强调了精度和范围的影响。

被折叠的 条评论
为什么被折叠?



