Docsity

Assignment 2 Questions with Solutions - Computer Organization | CPSC 2105, Assignments of Computer Architecture and Organization

Toggle sidebar
bg1
CPSC 2105 Introduction to Computer Organization
Homework Set 2 Due Tuesday, September 5, 2006
Homework Key with Answers and Comments.
Each of these questions counts 25 points.
1. Represent the following numbers as 8–bit integers in two’s–complement form.
a) – 104 b) – 128 c) 120
ANSWER:
a) 104 = 64 + 40 = 64 + 32 + 8.
As an 8–bit binary number + 104 is 0110 1000.
The one’s complement 1001 0111
Add one to get 1001 1000. In hexadecimal 0x98.
b) – 128 as an 8–bit binary number is 1000 0000. Just memorize this.
COMMENT: Many students attempted to apply the standard method, first
converting +128 to an 8–bit binary number and then taking the
two’s–complement. This is not valid, as + 128 cannot be represented
as an 8–bit two’s–complement integer. I deducted 2 points for this.
c) 120 = 64 + 56 = 64 + 32 + 24 = 64 + 32 + 16 + 8.
As an 8–bit binary number + 120 is 0111 1000. In hexadecimal 0x78.
2. Represent the same numbers (from problem 1) as 16–bit integers in two’s–complement.
ANSWER: Just to show it can be done, we offer two distinct answers for each number.
a) – 104 as an 8–bit two’s–complement number 1001 1000
Extend the sign bit (leftmost bit) to get 1111 1111 1001 1000.
+ 104 as an 8–bit two’s–complement number 0110 1000
+ 104 as a 16–bit two’s–complement number 0000 0000 0110 1000
Take the one’s–complement 1111 1111 1001 0111
Add one 1111 1111 1001 1000
b) – 128 as an 8–bit binary number is 1000 0000
Extend the sign bit (leftmost bit) to get 1111 1111 1000 0000.
+ 128 cannot be represented in 8 bits
+ 128 as a 16–bit two’s–complement number 0000 0000 1000 0000
Take the one’s–complement 1111 1111 0111 1111
Add one 1111 1111 1000 0000
c) + 120 as an 8–bit two’s–complement number 0111 1000
+ 120 as a 16–bit two’s–complement number 0000 0000 0111 1000
pf2

Partial preview of the text

Download Assignment 2 Questions with Solutions - Computer Organization | CPSC 2105 and more Assignments Computer Architecture and Organization in PDF only on Docsity!

CPSC 2105 Introduction to Computer Organization

Homework Set 2 Due Tuesday, September 5, 2006

Homework Key with Answers and Comments.

Each of these questions counts 25 points.

  1. Represent the following numbers as 8–bit integers in two’s–complement form. a) – 104 b) – 128 c) 120 ANSWER: a) 104 = 64 + 40 = 64 + 32 + 8. As an 8–bit binary number + 104 is 0110 1000. The one’s complement 1001 0111 Add one to get 1001 1000. In hexadecimal 0x98. b) – 128 as an 8–bit binary number is 1000 0000. Just memorize this. COMMENT: Many students attempted to apply the standard method, first converting +128 to an 8–bit binary number and then taking the two’s–complement. This is not valid, as + 128 cannot be represented as an 8–bit two’s–complement integer. I deducted 2 points for this. c) 120 = 64 + 56 = 64 + 32 + 24 = 64 + 32 + 16 + 8. As an 8–bit binary number + 120 is 0111 1000. In hexadecimal 0x78.
  2. Represent the same numbers (from problem 1) as 16–bit integers in two’s–complement. ANSWER: Just to show it can be done, we offer two distinct answers for each number. a) – 104 as an 8–bit two’s–complement number 1001 1000 Extend the sign bit (leftmost bit) to get 1111 1111 1001 1000. + 104 as an 8–bit two’s–complement number 0110 1000 + 104 as a 16–bit two’s–complement number 0000 0000 0110 1000 Take the one’s–complement 1111 1111 1001 0111 Add one 1111 1111 1001 1000 b) – 128 as an 8–bit binary number is 1000 0000 Extend the sign bit (leftmost bit) to get 1111 1111 1000 0000. + 128 cannot be represented in 8 bits + 128 as a 16–bit two’s–complement number 0000 0000 1000 0000 Take the one’s–complement 1111 1111 0111 1111 Add one 1111 1111 1000 0000 c) + 120 as an 8–bit two’s–complement number 0111 1000 + 120 as a 16–bit two’s–complement number 0000 0000 0111 1000

ASCII Code Table We use the following ASCII codes in the next two problems. Character Decimal Code Hexadecimal Binary “ ” 32 0x20 0010 0000 “A” 65 0x41 0100 0001 “B” 66 0x42 0100 0010 “C” 67 0x43 0100 0011 “D” 68 0x44 0100 0100 “E” 69 0x45 0100 0101 “F” 70 0x46 0100 0110

  1. Give the ASCII code for the 9–character string “CAFE BABE”. This is eight printable characters and the blank character “ “. Use hexadecimal encodings, not the decimal encodings found in Table 2.7 on page 79 of the textbook. ANSWER: Just read the codes from the above table in order. Two answers are given. These are not equivalent, but as we have not yet defined byte ordering, either is acceptable. CAFE BABE is 43 41 46 45 20 42 41 42 45 This is also acceptable 45 42 41 42 20 45 46 41 43 COMMENT: Please note that the blank is a significant character in the string and must be encoded in its proper place. It is not sufficient to encode “CAFEBABE” and then note a code for the blank.
  2. Give the odd–parity 8–bit ASCII codes (in hexadecimal) for each of the following five characters: “C”, “A”, “F”, “E”, and “ ” (the blank). ANSWER: We use the following table. Character No Parity Odd Parity Hex Code Binary One bits Binary Hex “C” 43 0100 0011^3 0100 0011^43 “A” 41 0100 0001^2 1100 0001^ C “F” 46 0100 0110^3 0100 0110^46 “E” 45 0100 0101^3 0100 0101^45 “ ” 20 0010 0000^1 0010 0000^20 The following table is offered as extra material related to this question. No Parity Odd Parity Even Parity Character Hex Binary Binary Hex Binary Hex “ ” 0x20 0010 0000 0010 0000 0x20 1010 0000 0xA “A” 0x41 0100 0001 1100 0001 0xC1 0100 0001 0x “B” 0x42 0100 0010 1100 0010 0xC2 0100 0010 0x “C” 0x43 0100 0011 0100 0011 0x43 1100 0011 0xC “D” 0x44 0100 0100 1100 0100 0xC4 0100 0100 0x “E” 0x45 0100 0101 0100 0101 0x45 1100 0101 0xC “F” 0x46 0100 0110 0100 0110 0x46 1100 0110 0xC