{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

10-Subtraction-annot

10-Subtraction-annot - Negative Numbers and Subtraction...

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

Subtraction (lvk) 1 Negative Numbers and Subtraction Theadders wedesigned can add only non-negativenumbers If wecan represent negativenumbers, then subtraction is “just” theability to add two numbers (oneof which may benegative). We’ll look at threedifferent ways of representing signed numbers . How can wedeciderepresentation is better? Thebest oneshould result in thesimplest and fastest operations. This is just likechoosing a data structurein programming. We’remostly concerned with two particular operations: Negating a signed number, or converting x into -x. Adding two signed numbers, or computing x + y. So, wewill comparetherepresentation on how fast (and how easily) theseoperations can bedoneon them

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

View Full Document
Subtraction (lvk) 2 Signed magnitude representation Humans usea signed-magnitude system: weadd + or - in front of a magnitudeto indicatethe sign. Wecould do this in binary as well, by adding an extra sign bit to thefront of our numbers. By convention: A 0 sign bit represents a positivenumber. A 1 sign bit represents a negativenumber. Examples: 1101 2 = 13 10 (a 4-bit unsigned number) 0 1101 = +13 10 (a positivenumber in 5-bit signed magnitude) 1 1101 = -13 10 (a negativenumber in 5-bit signed magnitude) 0100 2 = 4 10 (a 4-bit unsigned number) 0 0100 = +4 10 (a positivenumber in 5-bit signed magnitude) 1 0100 = -4 10 (a negativenumber in 5-bit signed magnitude)
Subtraction (lvk) 3 Signed magnitude operations Negating a signed-magnitudenumber is trivial: just changethesign bit from 0 to 1, or vice versa. Adding numbers is difficult, though. Signed magnitudeis basically what peopleuse, so think about thegrade-school approach to addition. It’s based on comparing thesigns of theaugend and addend: If they havethesamesign, add themagnitudes and keep that sign. If they havedifferent signs, then subtract thesmaller magnitudefrom thelarger one. The sign of thenumber with thelarger magnitudeis thesign of theresult. 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. Wekeep thesign bits: 0 for positivenumbers, and 1 for negative. Thesign bit is complemented along with therest of thebits. Examples: 1101 2 = 13 10 (a 4-bit unsigned number) 0 1101 = +13 10 (a positivenumber in 5-bit one’s complement) 1 0010 = -13 10 (a negativenumber in 5-bit one’s complement) 0100 2 = 4 10 (a 4-bit unsigned number) 0 0100 = +4 10 (a positivenumber in 5-bit one’s complement) 1 1011 = -4 10 (a negativenumber in 5-bit one’s complement)
Subtraction (lvk) 5 Why is it called “one’s complement?” Complementing a singlebit is equivalent to subtracting it from 1. 0

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 ]}