CS 473 - HW1
Floating Point
For this assignment, you need to show all your work. In particular,
for the number base conversions you need to show the table you use for the
conversion; for the floating point arithmetic you need to divide the numbers
into sign-exponent-mantissa fields and manipulate the fields explicitly.
Yes, I really mean it, and the TA will take points off if you don't do
it.
- (32 points) Conversion from decimal to binary fractions.
| None of these result in a repetend. |
| a) 0.125 |
b) 0.25 |
c) 0.625 |
d) 0.4375
|
a)
| Old |
Bit
|
New
|
0.125
|
0
|
0.25
|
0.25
|
0
|
0.5
|
0.5
|
1
|
0
|
| Answer |
0.001 |
b)
| Old |
Bit
|
New
|
0.25
|
0
|
0.5
|
0.5
|
1
|
0
|
| Answer |
0.01
|
c)
| Old |
Bit
|
New
|
| 0.625 |
1
|
0.25
|
0.25
|
0
|
0.5
|
0.5
|
1
|
0
|
| Answer |
0.101 |
d)
| Old |
Bit
|
New
|
| 0.4375 |
0
|
0.875 |
0.875
|
1
|
0.75
|
0.75
|
1
|
0.5
|
0.5
|
1
|
0
|
| Answer |
0.0111 |
- (32 points) Conversion from binary to decimal fractions.
| a) 0.0101 |
b) 0.1101 |
c) 0.111 |
d) 0.011 |
a)
Bit
|
Old
|
New
|
1
|
0
|
0.5 |
0
|
0.5
|
0.25
|
1
|
.25
|
0.625
|
0
|
0.625
|
0.3125
|
| Answer |
0.3125 |
b)
Bit
|
Old
|
New
|
| 1 |
0
|
0.5 |
0
|
0.5
|
0.25
|
1
|
0.25
|
0.625
|
1
|
0.625
|
0.8125
|
| Answer |
0.8125 |
c)
Bit
|
Old
|
New
|
| 1 |
0
|
0.5 |
1
|
0.5
|
0.75
|
1
|
0.75
|
0.875
|
| Answer |
0.875 |
d)
Bit
|
Old
|
New
|
1
|
0
|
0.5 |
1
|
0.5
|
0.75
|
0
|
0.75
|
0.375
|
| Answer |
0.375 |
- (32 points) Floating Point Interpretation
| What are the values, in decimal, of the following
IEEE floating point numbers? |
| a) 42158000 |
b) c1990000 |
c) 00000000 |
d) bf800000 |
a) 42158000
It is 0100 0010 0001 0101 1000 0000 0000 0000, i.e. sign
=0; exp =132-127=5. Then we get 100101.011.
| Old |
Bit |
New |
| 0 |
1
|
1
|
1
|
0 |
2
|
2
|
0 |
4
|
4
|
1
|
9
|
9
|
0 |
18
|
18
|
1 |
37
|
| Answer |
37
|
and
Bit
|
Old
|
New
|
1
|
0
|
0.5 |
1
|
0.5
|
0.75
|
0
|
0.75
|
0.375
|
| Answer |
0.375 |
The final answer is 37.375.
b) c1990000
It is 1100 0001 1001 1001 0000 0000 0000 0000, i. e. sign
=1, exp = 131-127=4. Then we get - 10011.001.
| Old |
Bit |
New |
| 0 |
1
|
1
|
1
|
0 |
2
|
2
|
0 |
4
|
4
|
1
|
9
|
9
|
1
|
19
|
| Answer |
19
|
and
Bit
|
Old
|
New
|
| 1 |
0
|
0.5 |
0
|
0.5
|
0.25
|
0
|
0.25
|
0.125
|
| Answer |
0.125 |
The final answer is -19.125.
c) 00000000
It is 0000 0000 0000 0000 0000 0000 0000 0000, i.e. 0. And
the final answer is 0.
d) bf800000
It is 1011 1111 1000 0000 0000 0000 0000 0000, i.e. sign
=1, exp =127-127=0. Then we get -1.
| Old |
Bit |
New |
| 0 |
1
|
1
|
| Answer |
1 |
The final answer is -1.
- (32 points) Conversion to Floating Point
| What is the IEEE floating point representation
of the following decimal floating point numbers? |
| a) 17.125 |
b) -11.375 |
c) 0.175 |
d) -31.5 |
a) 17.125
| Old |
New |
Bit |
| 17 |
8
|
1 |
| 8 |
4 |
0 |
| 4 |
2
|
0 |
| 2 |
1
|
0
|
1
|
0
|
1
|
| Answer |
10001 |
and
| Old |
Bit
|
New
|
0.125
|
0
|
0.25
|
0.25
|
0
|
0.5
|
0.5
|
1
|
0
|
| Answer |
0.001 |
We get 10001.001, i.e. sign =0, exp = 127+ 4 = 131. Then we can get 0100
0001 1000 1001 0000 0000 0000 0000. The final answer is 41890000.
b) -11.375
| Old |
New |
Bit |
| 11 |
5
|
1 |
5
|
2
|
1
|
| 2 |
1
|
0
|
1
|
0
|
1
|
| Answer |
1011 |
and
| Old |
Bit
|
New
|
0.375
|
0
|
0.75
|
0.75
|
1
|
0.5
|
0.5
|
1
|
0
|
| Answer |
0.011 |
We get -1011.011, i.e. sign =1,exp =127+3 = 130. Then we can get 1100 0001
0011 0110 0000 0000 0000 0000. The final answer is c1360000.
c) 0.175
| Old |
Bit
|
New
|
0.175
|
0
|
0.35
|
0.35
|
0
|
0.7
|
0.7
|
1
|
0.4
|
0.4
|
0
|
0.8
|
0.8
|
1
|
0.6
|
0.6
|
1
|
0.2
|
0.2
|
0
|
0.4
|
0.4
|
0
|
0.8
|
0.8
|
1
|
0.6
|
0.6
|
1
|
0.2
|
0.2
|
0
|
0.4
|
0.4
|
0
|
0.8
|
0.8
|
1
|
0.6
|
0.6
|
1
|
0.2
|
0.2
|
0
|
0.4
|
0.4
|
0
|
0.8
|
0.8
|
1
|
0.6
|
0.6
|
1
|
0.2
|
0.2
|
0
|
0.4
|
0.4
|
0
|
0.8
|
0.8
|
1
|
0.6
|
0.6
|
1
|
0.2
|
0.2
|
0
|
0.4
|
0.4
|
0
|
0.8
|
0.8
|
1
|
0.6
|
0.6
|
1
|
0.2
|
| Answer |
0.00101100110011001100110011 |
We get 0.00101100110011001100110011, i.e. sign = 0, exp = 127 -3 =124.
Then we can get 0011 1110 0011 0011 0011 0011 0011 0011. The
final answer is 3e333333.
d) -31.5
| Old |
New |
Bit |
31
|
15
|
1 |
15
|
7
|
1
|
7
|
3
|
1
|
3
|
1
|
1
|
1
|
0
|
1
|
| Answer |
11111 |
and
| Old |
Bit
|
New
|
0.5
|
1
|
0
|
| Answer |
0.1 |
We get -11111.1, i.e. sign =1, exp = 127 + 5 =132. Then we can get 1100
0001 1111 1100 0000 0000 0000 0000. The final answer is c1fc0000.
- (64 points) Floating Point Arithmetic
| Perform the following arithmetic operations
in IEEE floating point (use the algorithms as presented in class;
don't convert to decimal, calculate the result,
and convert back). Your final result should be an eight digit hexadecimal
number |
| a) 41250000 + c1120000 |
b) c0cc0000 - 40080000 |
c) 41250000 * c1120000 |
d) 41ec0000 / c1600000 |
a) 41250000 + c1120000
41250000 is 0100 0001 0010 0101 0000 0000 0000 0000, i.e.
sign =0, exp = 130 -127 =3, mantissa = 1.0100101.
c1120000 is 1100 0001 0001 0010 0000 0000 0000 0000, i.e.
sign =1, exp = 130 -127 =3, mantissa = 1.001001.
1.0100101
+(-)1.001001
------------- exp =3 => 1.0011
* 2 ^ 0 => sign =0, exp = 127+0 =127, mantissa = 1.0011
0.0010011
Then we have 0011 1111 1001 1000 0000 0000 0000 0000. The final answer
is 3f980000.
b) c0cc0000 - 40080000
c0cc0000 is 1100 0000 1100 1100 0000 0000 0000 0000, i.e.
sign =1, exp = 129 -127 =2, mantissa = 1.10011.
40080000 is 0100 0000 0000 1000 0000 0000 0000 0000, i.e.
sign =0, exp = 128 -127 =1, mantissa =1.0001.
-1.10011
- 0.10001
-------------- exp = 2 => -1.0001 * 2 ^ 3
=> sign =1, exp = 127+3 =130, mantissa = 1.0001
- 10.00100
Then we have 1100 0001 0000 1000 0000 0000 0000 0000. The final answer
is c1080000.
c) 41250000*c1120000
41250000 is 0100 0001 0010 0101 0000 0000 0000 0000, i.e.
sign =0, exp = 130, mantissa = 1.0100101.
c1120000 is 1100 0001 0001 0010 0000 0000 0000 0000, i.e.
sign =1, exp = 130, mantissa = 1.001001.
exp: 10000010
mantissa: 1.0100101
sign: 1
+ 10000010
* 1.001001
---------------
-------------
100000100
1.0100101
-
01111111
0.0010100101
----------------
0.0000010100101
10000101
-----------------
1.0111100001101
Then we have 1100 0010 1011 1100 0011 0100 0000 0000. The
final answer is c2bc3400.
d) 41ec0000/c160000
41ec0000 is 0100 0001 1110 1100 0000 0000 0000 0000, i.e.
sign =0, exp = 131, mantissa = 1.11011.
c1600000 is 1100 0001 0110 0000 0000 0000 0000 0000, i.e.
sign =1, exp = 130, mantissa = 1.11.
exp: 10000011
mantissa:
1.00001101101101101101101
sign: 1
- 10000010
____________________________
-------------
1.11
) 1.1101100000000000000000000
00000001
1 11
+ 01111111
------
-------------
01100
10000000
111
-------
1010
111
--------
1100
111
-------
1010
111
--------
1100
111
-------
1010
111
--------
1100
...
Then we have 1100 0000 0000 0110 1101 1011 0110 1101. The final answer is
c006db6d.