{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

10-Subtraction

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

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

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

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

View Full Document
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)
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

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

View Full Document
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)
Subtraction (lvk) 5 Why is it called “one’s complement?” Complementing a single bit is equivalent to subtracting it from 1. 0 ’ = 1

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### 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
Ask a homework question - tutors are online
{"found_math": false, "script_math_tex": 0, "script_math_asciimath": 0, "math_annotations": 0, "math_alttext": 0, "mathml": 0, "mathjax_tag": 0, "mathjax_inline_tex": 0, "mathjax_display_tex": 0, "mathjax_asciimath": 0, "img_math": 0, "codecogs_latex": 0, "wp_latex": 0, "mimetex.cgi": 0, "/images/math/codecogs": 0, "mathtex.cgi": 0, "katex": 0, "math-container": 0, "wp-katex-eq": 0, "align": 0, "equation": 0, "x-ck12": 0, "texerror": 0}