Documenti di Didattica
Documenti di Professioni
Documenti di Cultura
These steps are applied to the binary number that is to be subtracted from another binary number, as demonstrated below. Applying these steps allows one to perform a subtraction by adding a negative binary number to a positive binary number, a slight advantage, since the process for adding binary numbers is a bit less complicated than that of subtracting binary numbers. Also, this method eliminates the need to keep track of the "debt" that in some cases must be created in position 9 in a binary number when eight-bit binary numbers are subtracted (or in position n+1 for n-bit binary numbers) when using the "standard" method for binary subtraction. This method simply focuses on performing the subtraction directly for one column (position) at a time.
Document Structure
For the sake of facilitating the comprehension of the content in this document, a following graphical view of the structure of the document is shown in Fig. 1. One of the reasons for including the graph is the difference in the calculation steps required depending on whether the result of the subtraction is positive or negative.
Fig. 1
Example 1: Positive Result The C1 Step The C2 Step Performing the Subtraction Summary of Subtraction Method when Result is Positive
Introduction
Document Structure
Examples
www.dabbleklix.com
12/03/07
Notations
For the sake of simplicity and consistency, the following notations will be used in this document: C1 = The "1's complement" step C2 = The "2's complement" step n10 = Indicates that the number (decimal system) n2 = Indicates that the number system) n n is a number in the 10-Base system
A number that consists of 0's and 1's only is always a binary number unless otherwise specified.
Examples
In order to facilitate the explanation the "2's complement" subtraction method, the following examples, one with a positive result, and one with a negative result, will be used: Example 1: 12210-4610=7610 Example 2: 4610-12210 = -7610
Complementing each 0 with a 1, and each 1 with a 0 in the binary number in Line 1 results in 0 1 0 1 1 0 0 1 1 0 1 0 1 0 0 1 C1 4610 20910 (Line 2) (Line 3)
Note that the binary number represented by C1 in Line 3 represents the value 20910 since the C1 step always results in the value
www.dabbleklix.com
12/03/07
111111112 = 25510
(Line 4)
because the sum of the binary numbers in Line 2 and Line 3 is always 11111111, as shown below. 0 1 1 0 1 1 1 0 1 0 1 1 1 0 1 1 0 1 1 0 1 0 1 1 C1 4610 20910 25510 (Line 5) (Line 6) (Line 7)
Thus, the C1 step always results in the number 25510-n10 where n10 is the original binary number to which the C1 step is applied, as demonstrated in Line 2 and 3.
Note that adding the binary numbers in Line 5 and Line 10 results in 0 1 1 0 0 1 0 1 0 0 0 1 0 1 0 0 1 0 0 1 1 0 0 0 0 4610 21010 25610 =-4610 (Line 11) (Line 12) (Line 13)
Note that this transaction resulted in the creation of one quantity 29 in position 9. This quantity is a "debt", as shown in the equation in Line 18.
www.dabbleklix.com
12/03/07
Note that Line 13 equals the sum of the binary numbers in Line 14 and Line 15. 1 1 1 1 1 1 1 1 1 1 0 0 0 0 0 0 0 0 25510 110 25610 (Line 14) (Line 15) (Line 16)
using the binary number for the value -4610 in Line 12 actually reflects the subtraction 12210 + 21010 - 25610 = 7610 (Line 18)
since the C1 and C2 steps have increased the value of the original binary number for 4610 by a quantity of 29 = 25610 in Line 13, as shown by adding the binary numbers in Line 11 and Line 12. The binary digit quantity 12 in position 9 in Line 13 is a "debt", and is, therefore, negative, as shown in the equation in Line 18. The value -4610 comes from the last two terms on the left-hand side in the equation in Line 18, as follows: 21010 - 25610 = -4610 (Line 19) Thus, it is the creation of a "debt", equal to 29 = 25610, in position 9 that causes the binary number in Line 10 to function as if it had the value -4610. Line 10 actually represents the result of the equation in Line 19. The subtraction, represented by the equation in Line 17, mathematically takes on the 10-base format 12210 +(- 4610) = 7610 and the binary format 0 1 1 0 1 1 1 1 0 0 1 1 0 1 0 1 0 0 1 1 1 0 0 0 0 12210 21010 7610 = -4610 (Line 21) (Line 22) (Line 23) (Line 20)
Note that, in accordance with the format of the equation in Line 20, the binary numbers in Line 21 and Line 22 are added. Adding the values from position 1 through 8 in Line 23 and converting to 10-base yields the value 7610, which corresponds to the result from the equation in Line 20, and is, therefore, verified.
www.dabbleklix.com
12/03/07
The digit in position 8 is called the high bit. The digits in the positions 1 through 7 are called low bits. If the high bit in the result, in this case in Line 23, is a 0 (zero), the result is positive. If the high bit in the result is a 1 (one), the result is negative, s demonstrated in Example 2.
yields a negative result. It is, therefore, necessary to apply the C1 and C2 steps twice in order to arrive at the desired solution, as shown below.
The C1 step results in the value 13310, which is correct since the sum of the two binary numbers in Line 25 and Line 26 is 12210+13310=25510 (Line 27)
1 1
C1 C2
Note that the binary numbers in Line 32 and Line 33 are added. Converting the binary number in Line 33 encompassing position 1 through 8 to a 10-base number results in the value 18010. However, the debt of 25610 created in the C2 step (compare Example 1, Lines 11 and 12) is reflected by the value 1 in position 9 in Line 33. Thus, one obtains 18010 -25610=-7610 (Line 34)
Since it is cumbersome to have to remember the "debt" in position 9 in Line 33 when converting the binary number to a 10-base value, applying the C1 and the C2 steps once more, as follows, eliminates the "debt":
www.dabbleklix.com
12/03/07
Converting the binary value in Line 39 to a number in the 10-base system yields the value 7610. However, since the high bit in position 8 in Line 39 is a 0 (zero), the value is negative, that is, -7610.
www.dabbleklix.com
12/03/07