
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