This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.
View Full Document
Unformatted text preview: CS 231 Spring 2011 Homework 5 Solutions Addition and Subtraction 1. (10 pts) Change the following numbers to the specified format: a. 35 10 to 8bit One's Complement Binary Solution: +39 to binary is 0010 0111, then complement bits to get to One's Complement: 1101 1000 b. 123 10 to 8bit Two's Complement Binary Solution: +123 to binary is 0111 1011, then complement bits to get 1000 0100, now add 1 to get: 1000 0101 c. 63 10 to 8bit Two's Complement Binary Solution: +69 in 8bit Two's Complement format is the same as unsigned binary, so we convert as usual and get: 0100 0101 d. 1101 0101 from 8bit Two's Complement Binary into Decimal Solution: To find the magnitude, we must first convert it to a positive number. Complement bits to get 0010 1010, then add 1 to get 0010 1011. This has a magnitude of 43, we were looking for a negative number: 43 e. 1000 0110 from 8bit Two's Complement Binary into One's Complement Binary Solution: First Method Make the number positive by flipping the bits to get 0111 1001, and then adding 1 to get 0111 1010. Now flip the bits back to get One's Complement: 1000 0101 Second Method Just subtract 1 and get: 1000 0101 2. (15 pts) Assume the following are 8bit numbers in 2's complement format. Perform the computations below to produce 8bit results. For each part, show the results of your computation, indicate whether the operation overflows, and convert the operands and results to decimal to check the computation. a. 1010 0111 + 1011 0111 Solution: Note that here we are adding a negative and a negative number, so overflow is a possibility. 10100 111 Decimal 1010 0111 88 +1011 0111 +(72)  0101 1110 +94 (INCORRECT ANSWER) There is OVERFLOW; you can tell because the sign bit changed. The conversion to decimal also verifies that the answer is incorrect.also verifies that the answer is incorrect....
View
Full
Document
This note was uploaded on 04/28/2011 for the course CS 231 taught by Professor Staff during the Spring '08 term at University of Illinois, Urbana Champaign.
 Spring '08
 Staff

Click to edit the document details