Computer Architecture 1
Computer Architecture 1
Question 1 (4 points)
Convert the following decimal numbers to their 2’s complement representations (use 8 bits for each
number and truncate the fractional digits if necessary):
a) 102.3
b) 6.3
c) −13
d) 0.04
Solution:
a) 01100110 - As we can only use 8 bits, we have had to truncate all the fractional digits.
b) 0110.0100 - As we can only use 8 bits, we have had to truncate.
c) 11110011
d) 0.0000101 - As we can only use 8 bits, we have had to truncate.
Question 2 (6 points)
Perform the following operation in 2’s complement. Indicate when an overflow happens.
a) 11001010 + 11101010
b) 01011010 + 00110101
c) 0011.1100 + 0100.0100
d) 11010111 − 00001011
Solution:
a) 10110100
b) 10001111 - There is overflow.
c) 1000.0000 - There is overflow.
d) = 11010111 + 11110101 = 11001100
1
Computer Architecture Homework 1
b) −0.028
Solution:
Solution:
2
Computer Architecture Homework 1
b) Assume 32-bit words are used for communicating messages. Furthermore, assume the charac-
ter codes cannot span over multiple words. Show how the following message is encoded, and
what will be its equivalence in hexadecimal.
THIS IS A SAMPLE STRING. OR IS IT?
Solution:
a) We have to encode 29 symbols. Each bit can only have two possible values and 24 =
16 < 29 < 25 = 32. Therefore, we would need 5 bits.
b) First, we are going to encode each symbol as a 5-bit pattern
Character bit-pattern
A 00000
B 00001
c 00010
D 00011
E 00100
F 00101
G 00110
H 00111
I 01000
J 01001
K 01010
L 01011
M 01100
N 01101
O 01110
P 01111
Q 10000
R 10001
S 10010
T 10011
U 10100
V 10101
W 10110
X 10111
Y 11000
Z 11001
(space) 11010
. 11011
? 11100
3
Computer Architecture Homework 1
Then we have to convert these strings of bits into 32-bit words. However, since character
codes cannot span over multiple words we are missing 2 bits per word. Therefore, we
add two 0s at the beginning of each word except for the last one, since it only encodes 4
characters and we need 12 extra 0s at the beginning for it to be 32 bits long.
00100110 01110100 01001011 01001000
00100101 10100000 01101010 01000000
00011000 11110101 10010011 01010010
00100111 00010100 00110100 11011011
00110100 11101000 11101001 00010010
00000000 00001101 00100010 01111100
And its conversion to hexadecimal notation is the following:
26744B48 25A06A40 18F59352 271434DB 34E8E912 000D227C
4
Computer Architecture Homework 1
Figure 1
Solution:
a) The output is 1
b) The output is 0
The circuit gives the following outputs for these possible inputs:
a1 a2 a3 a4 output
0 0 0 0 0
0 0 0 1 1
0 0 1 0 1
0 0 1 1 1
0 1 0 0 0
0 1 0 1 0
0 1 1 0 0
0 1 1 1 1
1 0 0 0 0
1 0 0 1 1
1 0 1 0 0
1 0 1 1 1
1 1 0 0 0
1 1 0 1 0
1 1 1 0 0
1 1 1 1 0
From this we can conclude that the circuit compares the 2-bit numbers a and b. It outputs 1
if at least one of the digits of a is 0 and at least one of the digits of b is 1, and 0 otherwise.
5
Computer Architecture Homework 1
Solution:
Figure 2
Solution:
6
Computer Architecture Homework 1
Figure 3
Where A0, A1, A2 and A3 are the binary digits from the input and B0, B1, B3 and B4 the
binary digits from the output.
Solution:
7
Computer Architecture Homework 1
Figure 4
First, shift the decimal point of the smaller number to equalize the exponents:
1.34021 · 103
Follow the procedure described above to add the following numbers:
N = 14.25, M = 0.5
a) Convert the numbers to IEEE floating point format.
b) Add the numbers.
c) Normalize the result to put it in IEEE format again.
Solution:
a) 14.25
Sign bit: the number is positive so 0
Number in binary: 1110.01
Fraction field with the leftmost 1: 111001000000000000000000
14.25(10) = 1110.01(2) = 1.11001(2) · 23
Exponent field: 10000010 (as 8-bit excess notation corresponds to 3).
Result: 01000001011001000000000000000000
8
Computer Architecture Homework 1
0.05
Sign bit: the number is positive so 0
Number in binary: 0.1
Fraction field with the leftmost 1: 10000000000000000000000
0.5(10) = 0.1(2) = 1.0(2) · 2−1
Exponent field: 01111110 (as 8-bit excess notation corresponds to -1).
Result: 00111111000000000000000000000000
b) 14.25(10) +0.5(10) = 1.11001(2) ·23 +1.0(2) ·2−1 = 1.11001(2) ·23 +0.0001·23 = 1.11011(2) ·23
c) Sign bit: 0
Fraction field with the leftmost 1: 111011000000000000000000
Exponent field: 10000010 (as 8-bit excess notation corresponds to 3).
Result: 01000001011011000000000000000000