COMP2421 Assignment 1
Question 1
Convert the binary number to decimal number:
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:
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
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
...
So we can know:
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:
, so we can get:
. Then calculate value of e� by subtracting the bias:
Finally, the real number is:
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
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
...
So we can know:
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
The single-precision value without rounding is: 3.141592502593.14159250259. Then calculate the accuracy:
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
The single-precision value is: 3.14159274101257324218753.1415927410125732421875. Then calculate the accuracy:
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.