Docsity

Midterm Exam with Solution for Computer Organization | CPSC 2105, Exams of Computer Architecture and Organization

Toggle sidebar
bg1
CPSC 2105 Introduction to Computer Organization
Take-Home Midterm Due at 1:00 PM on Monday March 13, 2006
SHOW ALL OF YOUR WORK.
NO CREDIT GIVEN FOR ANSWERS THAT SHOW NO WORK.
DO NOT PLACE ANY WORK ON THIS SHEET.
1. (10 points) What is the range of integers that can be represented in 12 binary bits
a) if the integers are stored as unsigned numbers?
b) if the integers are stored as two’s–complement signed numbers?
ANSWER: In this, we recall that 212 = 4096 and 211 = 2048.
a) Unsigned N–bit integers range from 0 to 2N – 1, so 12–bit integers
range from 0 to 212 – 1 or 0 to 4095.
b) Signed N–bit integers in two’s complement form range from –2N–1 to 2N–1 –1.
For 12–bit numbers, this is –211 to 211 –1, or –2048 to 2047.
2. (10 points) Convert the following decimal integers to 12–bit two’s–complement form.
Show your work as most calculator will do this automatically.
a) 1023 b) – 1984
ANSWER: We first convert to binary and then pad out to 12 bits.
a) 1023 = 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
= 29 + 28 + 27 + 26 + 25 + 24 + 23 + 22 + 21 + 20
= 11 1111 1111 = 0011 1111 1111, or 0x3FF.
b) 1984 = 1024 + 960 = 1024 + 512 + 448
= 1024 + 512 + 256 + 192 = 1024 + 512 + 256 + 128 + 64
= 1210 +129 + 128 + 127 + 126 + 025 + 024 + 023 + 022 + 021 + 020
= 11111 000000 = 0111 1100 0000
One’s complement is 1000 0011 1111
Add 1 to get 1000 0100 0000, or 0x840.
One could also notice that 1984 = 31 64 = 31 26, so we first covert 31 to 1 1111 and
put six zeroes after it to get 1 1111 000000 or 0111 1100 0000.
Note also that the 12–bit binary number 1000 0100 0000 has six zeroes at its end, so we
divide by 26 = 64 to get 1111 1110 0001, this being 1000 01 with the sign bit copied to
to fill in the first six positions.
Let – X = 1111 1110 0001
One’s complement 0000 0001 1110
Add one 0000 0001 1111, or 31.
100, 100, 99, 99, 98, 98, 95, 95, 95, 95, 92.
86, 85, 84, 81, 79, 68, 45
Page 1 of 6 pages Exam Key Revised on March 14, 2006
pf3
pf4
pf5

Partial preview of the text

Download Midterm Exam with Solution for Computer Organization | CPSC 2105 and more Exams Computer Architecture and Organization in PDF only on Docsity!

CPSC 2105 Introduction to Computer Organization

Take-Home Midterm Due at 1:00 PM on Monday March 13, 2006

SHOW ALL OF YOUR WORK.

NO CREDIT GIVEN FOR ANSWERS THAT SHOW NO WORK.

DO NOT PLACE ANY WORK ON THIS SHEET.

  1. (10 points) What is the range of integers that can be represented in 12 binary bits a) if the integers are stored as unsigned numbers? b) if the integers are stored as two’s–complement signed numbers? ANSWER: In this, we recall that 2^12 = 4096 and 2^11 = 2048. a) Unsigned N–bit integers range from 0 to 2N^ – 1, so 12–bit integers range from 0 to 2^12 – 1 or 0 to 4095. b) Signed N–bit integers in two’s complement form range from –2N–1^ to 2N–1^ –1. For 12–bit numbers, this is –2^11 to 2^11 –1, or –2048 to 2047.
  2. (10 points) Convert the following decimal integers to 12–bit two’s–complement form. Show your work as most calculator will do this automatically. a) 1023 b) – 1984 ANSWER: We first convert to binary and then pad out to 12 bits. a) 1023 = 512 + 256 + 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 2^9 + 2^8 + 2^7 + 2^6 + 2^5 + 2^4 + 2^3 + 2^2 + 2^1 + 2^0 = 11 1111 1111 = 0011 1111 1111, or 0x3FF. b) 1984 = 1024 + 960 = 1024 + 512 + 448 = 1024 + 512 + 256 + 192 = 1024 + 512 + 256 + 128 + 64 = 1 210 +1 29 + 1 28 + 1 27 + 1 26 + 0 25 + 0 24 + 0 23 + 0 22 + 0 21 + 0 20 = 11111 000000 = 0111 1100 0000 One’s complement is 1000 0011 1111 Add 1 to get 1000 0100 0000 , or 0x. One could also notice that 1984 = 31  64 = 31  26 , so we first covert 31 to 1 1111 and put six zeroes after it to get 1 1111 000000 or 0111 1100 0000. Note also that the 12–bit binary number 1000 0100 0000 has six zeroes at its end, so we divide by 2^6 = 64 to get 1111 1110 0001, this being 1000 01 with the sign bit copied to to fill in the first six positions. Let – X = 1111 1110 0001 One’s complement 0000 0001 1110 Add one 0000 0001 1111, or 31. 100, 100, 99, 99, 98, 98, 95, 95, 95, 95, 92. 86, 85, 84, 81, 79, 68, 45
  1. (10 points) Using eight hexadecimal digits, show the IEEE–754 Single–Precision representation of the decimal number – 0.03125 (It is negative). ANSWER: First look at 0.03125 = 1/32 = 2–5^ = 1.000 2 – So E = – 5, M = 0000, and S = 1 (for negative). Done the mechanical way, we have: 0.03125  2 = 0.0625 0 0.0625  2 = 0.125 0 0.125  2 = 0.25 0 0.25  2 = 0.5 0 0.5  2 = 1.0 1 And 0.03125 = 0.00001 2 = 1.000 2 –5^ , as derived by the short cut. E + 127 = 127 – 5 = 122, which is 64 + 59 = 64 + 32 + 16 + 8 + 2 + 0. This is 0 27 + 1 26 + 1 25 + 1 24 + 0 23 + 0 22 + 1 21 + 0 20 , or 0111 1010 S | E | M is 1 0111 1010 0000 Regroup to get 1011 1101 0000 0 In hexadecimal, this is 0xBD00, expanded to 0x BD00 0000. Remember that E + 127 must be represented as an eight bit number: 0111 1010.
  2. (10 points) Using eight hexadecimal digits, show the IEEE–754 Single–Precision representation of the decimal number 16.75. ANSWER: 16.75 = 16 + 0.5 + 0.25 = 1 0000.11 = 1.000011  24 S = 0 and M = 0000 1100. E = 4 and E + 127 = 131 = 128 + 3. In binary, E + 127 = 1000 0011. S | E | M is 0 1000 0011 0000 1100 Regroup to get 0100 0001 1000 0110 0 In hexadecimal, this is 0x4186, expanded to 0x 4186 0000.
  3. (10 points) Using eight hexadecimal digits, show the ASCII code representation of the four–character string “1024”. Hint: This only looks like a number. ANSWER: The ASCII codes are ‘0’ = 0x30, ‘1’ = 0x31, ‘2’ = 0x32, and ‘4’ = 0x34. The answer is 0x3130 3234. Another acceptable answer is 0x3234 3130. This last answer is due to the issue in byte ordering called “Big Endian vs. Little Endian”.

Here is the algebraic proof that (X  Y)  Z = X  (Y  Z):

(X  Y)  Z =  X  YZ + (X  Y) Z

= ^ X^ ^ YXYZ + ( X Y + X Y ) Z , by definition.

We now apply DeMorgan’s Law that  A  B= A  B ,

with A = (^) X Y and B = X (^) Y.

= ^ X^ ^ Y ^ X^ ^ YZ + ( X^ Y + X Y^ ) Z

We next apply DeMorgan’s Law that  A  B= A + B ,

first with A = X and B = Y, so that  X  Y= X + Y = X + Y ,

then with A = X and B = Y , so that  X  Y= X + Y = X +Y

= (X + Y )( X + Y)Z + ( X Y + X Y ) Z

We thus have (X  Y)  Z = (X + Y^ )( X^ + Y)Z + ( X^ Y + X Y^ ) Z^. We shall use

this form again soon, but now continue to simplify the expression.

(X  Y)  Z = (X + Y^ )( X^ + Y)Z + ( X^ Y + X Y^ ) Z

= X X Z + XYZ + Y  X Z + Y YZ + X Y Z + X Y  Z

= X  Y Z + X Y  Z + X Y Z + XYZ

= X  Y Z + X Y Z + X Y  Z + XYZ, put in standard

order. We now use the commutative property that A  B = B  A with A = X and B = (Y  Z) to consider X  (Y  Z) = (Y  Z)X.

If (X  Y)  Z = X  Y Z + X Y Z + X Y  Z + XYZ,

then (Y  Z)  X = Y  Z X + Y Z X + Y Z  X + YZX

And (Y  Z)  X = X Y  Z + X  Y Z + X Y Z + XYZ

= X  Y Z + X Y Z + X Y  Z + XYZ, put in standard

order. The two expressions are equal, so (X  Y)  Z = X  (Y  Z).

  1. (10 points) Consider the following truth table, which purports to represent a Boolean function of two Boolean variables: X and Z. It has been written with 8 columns and 3 Boolean variables, X, Y, and Z. Rewrite this as an equivalent four–row truth table. X Y Z F(X, Z) 0 0 0 0 0 0 1 1 0 1 0 0 0 1 1 1 1 0 0 1 1 0 1 0 1 1 0 1 1 1 1 0 ANSWER: First reorder the truth table to show that there is no dependence on Y. X Y Z F 0 0 0 0 0 1 0 0 0 0 1 1 0 1 1 1 1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 0 Now trim the table by omitting every other row and the column labeled Y. X Z F(X, Z) 0 0 0 0 1 1 1 0 1 1 1 0
  2. (10 points) How many rows are in the truth table for the Boolean function F(U, V, X, Y, Z), where all variables are Boolean? ANSWER: Five variables mean 2^5 = 32 rows in the truth table.