Addition and Subtraction
Outline Arithmetic Operations (Section 1.2) – Addition – Subtraction – Multiplication Complements (Section 1.5) – 1’s complement – 2’s complement Signed Binary Numbers (Section 1.6) – 2’s complement – Addition – Subtraction
Addition Rules – Any carry obtained in a given significant position is used by the pair of digits one significant position higher
Subtraction The borrow in a given significant position adds 2 to a minuend digit
Multiplication 1011 X 101
Complement 1’s complement 2’s complement
1’s complement Rule: 1’s complement of a binary number is formed by changing – 1’s to 0’s – 0’s to 1’s → →
2’s Complement Alternative Method – Write the 1’s complement – Add 000…1 to 1’s complement Example – – (1’s complement) – (2’s complement)
Unsigned Subtraction X-Y – Determine Y’s 2’s complement – X+(2’s complement of Y) If X is larger or equal to Y, an end carry will result. Discard the end carry. If X is less than Y, no end carry will result. To obtain the answer in a familiar form, take the 2’s complement of the sum and place a negative sign in front.
Subtraction of Unsigned Number Example 1.7 (2’s complement) X= Y= X-Y (Discard end carry) Y-X (No end carry)
Signed Binary Number Signed-magnitude representation Signed 1’s complement representation Signed 2’s complement representation
Signed Magnitude Representation Rules – Represent the sign in the leftmost position – 0 for positive – 1 for negative Example – 01001↔(+)9 – 11001↔(-)9 Used in ordinary arithmetic, but not in computer arithmetic
Interpretation The user determines whether the number is signed or unsigned – (unsigned binary) +9 (signed binary) – (unsigned binary) -9 (signed binary)
Signed Complement System A signed complement system negates a number by taking its complement Example – (9) – (-)9 in signed 1’s complement – (-)9 in signed 2’s complement Usage: – 1’s complement: Seldom used – 2’s complement: Most common
Arithmetic Addition The rule for adding signed numbers in 2’s complement form is obtained from addition of two numbers A carry out of the sign bit is discarded In order to obtain correct answer, we must ensure that the result has a sufficient number of bits to accommodate the sum Useful Facts – Positive numbers have 0 in the leftmost bit – Negative numbers have a 1 in the leftmost bit
Negative Number Determine the value of a negative number in signed 2’s complement by converting the number to a positive number to place it in a more familiar form – is negative because the left most bit is 1. – 2’s complement: (+7) – Therefore, is -7