10-Subtraction - Negative Numbers and Subtraction The...

Info iconThis preview shows pages 1–6. Sign up to view the full content.

View Full Document Right Arrow Icon
Subtraction (lvk) 1 Negative Numbers and Subtraction The adders we designed can add only non-negative numbers If we can represent negative numbers, then subtraction is “just” the ability to add two numbers (one of which may be negative). We’ll look at three different ways of representing signed numbers . How can we decide representation is better? The best one should result in the simplest and fastest operations. This is just like choosing a data structure in programming. We’re mostly concerned with two particular operations: Negating a signed number, or converting x into -x. Adding two signed numbers, or computing x + y. So, we will compare the representation on how fast (and how easily) these operations can be done on them
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Subtraction (lvk) 2 Signed magnitude representation Humans use a signed-magnitude system: we add + or - in front of a magnitude to indicate the sign. We could do this in binary as well, by adding an extra sign bit to the front of our numbers. By convention: A 0 sign bit represents a positive number. A 1 sign bit represents a negative number. Examples: 1101 2 = 13 10 (a 4-bit unsigned number) 0 1101 = +13 10 (a positive number in 5-bit signed magnitude) 1 1101 = -13 10 (a negative number in 5-bit signed magnitude) 0100 2 = 4 10 (a 4-bit unsigned number) 0 0100 = +4 10 (a positive number in 5-bit signed magnitude) 1 0100 = -4 10 (a negative number in 5-bit signed magnitude)
Background image of page 2
Subtraction (lvk) 3 Signed magnitude operations Negating a signed-magnitude number is trivial: just change the sign bit from 0 to 1, or vice versa. Adding numbers is difficult, though. Signed magnitude is basically what people use, so think about the grade-school approach to addition. It’s based on comparing the signs of the augend and addend: If they have the same sign, add the magnitudes and keep that sign. If they have different signs, then subtract the smaller magnitude from the larger one. The sign of the number with the larger magnitude is the sign of the result. This method of subtraction would lead to a rather complex circuit. + 3 7 9 + - 6 4 7 - 2 6 8 5 1 3 1 7 6 4 7 - 3 7 9 2 6 8 because
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Subtraction (lvk) 4 One’s complement representation A different approach, one’s complement , negates numbers by complementing each bit of the number. We keep the sign bits: 0 for positive numbers, and 1 for negative. The sign bit is complemented along with the rest of the bits. Examples: 1101 2 = 13 10 (a 4-bit unsigned number) 0 1101 = +13 10 (a positive number in 5-bit one’s complement) 1 0010 = -13 10 (a negative number in 5-bit one’s complement) 0100 2 = 4 10 (a 4-bit unsigned number) 0 0100 = +4 10 (a positive number in 5-bit one’s complement) 1 1011 = -4 10 (a negative number in 5-bit one’s complement)
Background image of page 4
Subtraction (lvk) 5 Why is it called “one’s complement?” Complementing a single bit is equivalent to subtracting it from 1. 0 ’ = 1
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 6
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 10/19/2011 for the course CS 231 taught by Professor - during the Spring '08 term at University of Illinois at Urbana–Champaign.

Page1 / 30

10-Subtraction - Negative Numbers and Subtraction The...

This preview shows document pages 1 - 6. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online