# Computer Archtiecture HW3 ## 1 ``` ``` --- ## 2 | iteration | Step | Multiplier | Multiplicand | Product | |:--------- |:--------------------------- |:----------:|:------------:|:--------:| | 0 | Initial Value | 0110 | 00000101 | 00000000 | | 1 | 1 : 0->no operation | 0110 | 00000101 | 00000000 | | 1 | 2 : Shift left Multiplicand | 0110 | 00001010 | 00000000 | | 1 | 3 : Shift right Multiplier | 0011 | 00001010 | 00000000 | | 2 | 1a: 1->P+=Multiplicand | 0011 | 00001010 | 00001010 | | 2 | 2 : Shift left Multiplicand | 0011 | 00010100 | 00001010 | | 2 | 3 : Shift right Multiplier | 0001 | 00010100 | 00001010 | | 3 | 1a: 1->P+=Multiplicand | 0001 | 00010100 | 00011110 | | 3 | 2 : Shift left Multiplicand | 0001 | 00101000 | 00011110 | | 3 | 3 : Shift right Multiplier | 0000 | 00101000 | 00011110 | | 4 | 1 : 0->no operation | 0000 | 00101000 | 00011110 | | 4 | 2 : Shift left Multiplicand | 0000 | 01010000 | 00011110 | | 4 | 3 : Shift right Multiplier | 0000 | 01010000 | 00011110 | 0101 x 0110 = 00011110 --- ## 3 ### a | Hex | Binary | Decimal(2’s complement) | Decimal(unsigned) | |:-------- |:---------------------------------------:|:-------------------------:|:-----------------:| | 013462FD | 0000 0001 0011 0100 0110 0010 1111 1101 | 20210429 | 20210429 | The result is same as the two’s complement. ### b | Hex | Binary | Decimal(2’s complement) | Decimal(unsigned) | |:-------- |:---------------------------------------:|:-----------------------:|:-----------------:| | FECB9D03 | 1111 1110 1100 1011 1001 1101 0000 0011 | -20210429 | 4274756867 | The result is not same as the two’s complement. Because in this case the most left bit is 1, which is the sign bit in two’s complement. ### c | Hex | Binary | S | Exponent | Fraction | |:-------- |:----------------------------------:|:---:|:--------:|:-----------------------:| | 013462FD | 0 00000010 01101000110001011111101 | 0 | 00000010 | 01101000110001011111101 | | FECB9D03 | 1 11111101 10010111001110100000011 | 1 | 11111101 | 10010111001110100000011 | Bias = 127 ![](https://i.imgur.com/t5cit31.png) | Hex | Decimal(IEEE 754 float) | |:-------- |:-----------------------:| | 013462FD | 3.31317992256e-38 | | FECB9D03 | -1.35324267299e+38 | //Excat decimal nunber is caculated by IEEE 764 floating converter --- ## 4 ### a | Decimal | Binary | |:-------:|:----------------------------------:| | 68.32 | 0 10000101 00010001010001111010111 | S = 0 bias = 127 Exponent = 6+127 = 133 = 10000101 Fraction = 1.00010001010..... -1 = 00010001010001111010111 //Exact Fraction is caculated by IEEE 764 floating converter ### b | Decimal | Binary | |:--------:|:------------------------------------------:| | -126.751 | 0 10000000101 11111011000000010000011..... | S = 1 bias = 1023 Exponent = 6+1023 = 1029 = 10000000101 Fraction = 1.1111101100000..... -1 = 11111011000000010000011....(52 bits) ## 5 ### a a0 = (-1)^0 x 1.00000000 x 2^(-62) 0 0000001 00000000 ### b The largest denormalized number: a1 = (-1)^0 x 0.11111111 x 2^(-62) 0 0000000 11111111 The second largest denormalized number: a2 = (-1)^0 x 0.11111110 x 2^(-62) 0 0000000 11111110 ### c a0 和 a1在[8:0]是呈現完全相反的,或者從另一個角度來看a0 - 1 = a1 a0 = 0 0000001 00000000 a1 = 0 0000000 11111111 a1 和 a2只在最後一位一個是一,一個是零,從另一個角度來看a1 - 1 = a2 a1 = 0 0000000 11111111 a2 = 0 0000000 11111110 ### d 1 1111111 00000000 = -infinity 0 1111111 01010011 = NAN(*Not a Number*) --- ## 6 ### a 不可以,因為1/6是無限循環小數,所以用浮點數表示法,一定會有些表示誤差 用浮點數表示法會表示成 0 01111100 01010101010101010101011 實際值為0.16666667163372039794921875 與理論值0.166666666666666...有些許的誤差 ### b 實際作加法時 ``` 101010101010101010101011 + 101010101010101010101011 + 1010101010101010101010110 =10000000000000000000000001 fraction = 0000 0000 0000 0000 0000 0000 1<-這個1會捨去因為超出24bit的長度 ``` 最後結果為0 01111110 00000000000000000000000 正確答案為0 01111110 00000000000000000000000 兩者並沒有差