Boolean Algebra
     
      Binary subtraction
      The method of subtraction by adding the complement of the subtrahend applied to decimals
      The method of subtraction by adding the complement of the subtrahend applied to binary numbers
     
Binary subtraction
Computers perform binary subtraction by adding the minuend (M) and the complement of the subtrahend (the number to be subtracted).
The sum of the complement and the given number equals the corresponding place value (the particular power of the base of a counting system). 
The place values in the binary system are the powers of the base b = 2, just as the place values in the decimal system are the powers of ten.
Thus, for example the decimal complement of 79 is 21 since 79 + 21 = 100 = 102
The binary complement of 79 is 110001(49) since 1001111(79) + 110001(49) = 10000000(128) = 27.
The method of subtraction by adding the complement of the subtrahend applied to decimals:
 Example:  Calculate the difference D = A − B, where A = 423 minuend (M) and B = 79 subtrahend (S).
Solution:  423 79 = 423 + (100 79 100) = 423 + 21100 = 344, by using this method we can avoid 
subtraction of larger from smaller digits thus, when calculating the complement of the subtrahend (CS) we write 100 79 = 99 + 1 79 = 21.
The method of subtraction by adding the complement of the subtrahend applied to binary numbers:
Example:
 Calculate the difference D = A − B, where A = 101000(40) and B = 10111(23).
The calculation of the complement,  1000000 10111 = 111111 + 1 10111 = 101000 + 1 = 101001 (CS)
Solution:  101000 10111 = 101000 + (1000000 101111000000) = 101000 + 101001 1000000 = 10001
Proof: the binary complement of 10111(23) is 101001(41) since 10111(23) + 101001(41) = 1000000(64) = 26.
Computers form the complement in two steps, first invert all bits of the number by changing all of the ones to zeroes and all of the zeroes to ones (which is called one's complement). Then, add 1 to the result, thus forming, so called the two's complement of the given number.
Since computers use fixed-length fields, the complement from above example is shown in 8 bits:
0 0 0 1 0 1 1 1 (23) 
1 1 1 0 1 0 0 0 1's complement
+ 1

1 1 1 0 1 0 0 1 2's complement
0 0 0 1 0 1 1 1   (23)
+ 1 1 1 0 1 0 0 1  (133) CS

1 0 0 0 0 0 0 0 0 = 256 = 28
Then by adding the minuend and the complement of the subtrahend obtained is the difference. 
Notice that the leading 1 (overflow), that occurs in the highest-order bit of the result, equals the corresponding place value 28 which must be subtracted from the result as the above algorithm shows.  
0 0 1 0 1 0 0 0  Minuend
+ 1 1 1 0 1 0 0 1  CS

1 0 0 0 1 0 0 0 1  Result
Binary multiplication is the same as repeated binary addition, and binary division is the repeated process of subtraction, just as in decimal division.
Beginning Algebra Contents
Copyright © 2004 - 2020, Nabla Ltd.  All rights reserved.