COMP2421 Computer Organization

COMP2421 Assignment 1

Question 1

Convert the binary number to decimal number:

01110001two=1∗26+1∗25+1∗24+1∗20=113ten01110001���=1∗26+1∗25+1∗24+1∗20=113���
. For 8-bit word, complement to 28ten=256ten2���8=256���:
256ten−113ten=143ten256���−113���=143���
. Thus the value of 2's complement of 01110001two01110001��� in decimal is 143143.

Question 2

According to the straightforward approach for making two's complement, take the bitwise complement of the value and then add 1:

Bitwise complement of 10011101two10011101��� is: 01100010two01100010��� ;
then add 1: 01100010two+1=01100011two01100010���+1=01100011���.

Here, we get the 2's complement value of the given value in the question in binary, then convert it to decimal:

01100011two=1∗26+1∗25+1∗21+1∗20=99ten01100011���=1∗26+1∗25+1∗21+1∗20=99���
. Thus, the value of 2's complement of 10011101two10011101��� in decimal is 9999.

Question 3

The original real number is 111.111ten111.111���.

Get binary number for 111ten111���:
111=55∗2+1111=55∗2+1
55=27∗2+155=27∗2+1
27=13∗2+127=13∗2+1
13=6∗2+113=6∗2+1
6=3∗2+06=3∗2+0
3=1∗2+13=1∗2+1
1=0∗2+11=0∗2+1

111ten=1101111two111���=1101111���

Get binary number for .111ten.111���:
0.111∗2=0.2220.111∗2=0.222
0.222∗2=0.4440.222∗2=0.444
0.444∗2=0.8880.444∗2=0.888
0.888∗2=1.7760.888∗2=1.776
0.776∗2=1.5520.776∗2=1.552
0.552∗2=1.1040.552∗2=1.104
0.104∗2=0.2080.104∗2=0.208
0.208∗2=0.4160.208∗2=0.416
...

.111ten=.00011100011010100111111011111001110...two.111���=.00011100011010100111111011111001110...���

So we can know:

111.111ten=1101111.00011100...two=(−1)0∗1.10111100011100011...two∗26111.111���=1101111.00011100...���=(−1)0∗1.10111100011100011...���∗26
;
S=0�=0;
Fraction=101111000111000110101001111...��������=101111000111000110101001111...;
e=6�=6;
Exponent=e+bias=6+127=133ten=10000101two��������=�+����=6+127=133���=10000101���.

So the single-precision float is:
0 10000101 10111100011100011010100.

After optional rounding process, it can be:
0 10000101 10111100011100011010101.

Question 4

Original single-precision float is:

1011111110101010101010101010101010111111101010101010101010101010

, so we can get:
S=1�=1
;
(1)��������=.01010101010101010101010���(2)=2−2+2−4+2−6+2−8+2−10+2−12+2−14+2−16+2−18+2−20+2−22(3)=0.333333254���
;
Exponent=01111111two=127ten��������=01111111���=127���

. Then calculate value of e� by subtracting the bias:
e=Exponent−127=127−127=0�=��������−127=127−127=0
.

Finally, the real number is:

(4)�=(−1)�∗(1+��������)∗2�(5)=(−1)1∗1.333333254∗20(6)=−1.333333254���

Question 5

Represent pi using single-precision

The original real number is 3.1415926535ten3.1415926535���.

Get binary number for 3ten3���:
3=1∗2+13=1∗2+1
1=0∗2+11=0∗2+1

3ten=11two3���=11���

Get binary number for 0.1415926535ten0.1415926535���:
.1415926535∗2=.283185307.1415926535∗2=.283185307
.283185307∗2=.566370614.283185307∗2=.566370614
.566370614∗2=1.132741228.566370614∗2=1.132741228
.132741228∗2=.265482456.132741228∗2=.265482456
.265482456∗2=.530964912.265482456∗2=.530964912
.530964912∗2=1.061929824.530964912∗2=1.061929824
.061929824∗2=.123859648.061929824∗2=.123859648
...

.1415926535ten=0.001001000011111101101010100...two.1415926535���=0.001001000011111101101010100...���

So we can know:

(7)3.1415926535���=11.001001000011111101101...���(8)=(−1)0∗1.1001001000011111101101...���∗21
;
S=0�=0;
Fraction=1001001000011111101101010100010000010001011...��������=1001001000011111101101010100010000010001011...;
e=1�=1;
Exponent=e+bias=1+127=128ten=10000000two��������=�+����=1+127=128���=10000000���.

So the single-precision float for pi with 10 decimal places is:
0 10000000 10010010000111111011010
; while after rounding the last digit of the fraction, it's:
0 10000000 10010010000111111011011.

Evaluate accuracy

Accuracy for not rounded single-precision float

Convert the above single-precision float back to a real number:
.10010010000111111011010two=0.5707962512969970703125.10010010000111111011010���=0.5707962512969970703125

(9)�=(−1)0∗1.5707962512969970703125∗2128−127(10)=3.14159250259

The single-precision value without rounding is: 3.141592502593.14159250259. Then calculate the accuracy:

(11)�����=|������−��������������−�����������|∗100%/�����������(12)=|3.14159250259−3.1415926535|3.1415926535∗100%(13)=1.5091�−73.1415926535∗100%(14)=0.0000048036145%
.

Thus we can know the accuracy for using single-precision to express Pi value without rounding with 10 decimal places: the error is 0.0000048036145%0.0000048036145%, the accuracy is 99.9999951964%99.9999951964%.

Accuracy for rounded single-precision float

Convert the above rounded single-precision float back to a real number:

.10010010000111111011011two=0.57079637050628662109375.10010010000111111011011���=0.57079637050628662109375

(15)�=(−1)0∗1.57079637050628662109375∗2128−127(16)=3.1415927410125732421875
.

The single-precision value is: 3.14159274101257324218753.1415927410125732421875. Then calculate the accuracy:

(17)�����=|������−��������������−�����������|∗100%/�����������(18)=|3.1415927410125732421875−3.1415926535|3.1415926535∗100%(19)=.00000008751257323.1415926535∗100%(20)=0.00000278561172%
.

Thus we can know the accuracy for using single-precision to express Pi value with 10 decimal places: the error is 0.00000278561172%0.00000278561172%, the accuracy is 99.9999972144%99.9999972144%.

Notes: we can found that the accuracy after rounding is actually better than the solution without rounding.

发表评论

电子邮件地址不会被公开。 必填项已用*标注