From "Code"
🎧 Listen to Summary
Free 10-min PreviewSubtraction Using Complements
Key Insight
Traditional subtraction, which relies on 'borrowing', is mechanically complex for implementation with logic gates. To circumvent this, a technique that avoids borrowing through the use of number complements is applied. For decimal numbers, the 'nines' complement' is used: to subtract a subtrahend from a minuend (e.g., 176 from 253), the subtrahend (176) is subtracted from a string of 9s matching the digit count (e.g., 999), resulting in its nines' complement (823). This initial step ensures no borrowing is required.
Once the nines' complement of the subtrahend (823) is obtained, it is added to the original minuend (253 + 823 = 1076). The final difference is then found by adding 1 and subsequently subtracting a power of ten corresponding to the number of digits (e.g., 1076 + 1 - 1000 = 77). This method is mathematically sound, as `Minuend - Subtrahend` is equivalent to `Minuend + (999 - Subtrahend) + 1 - 1000`. If the subtrahend is larger than the minuend (e.g., 253 from 176), the initial steps are similar, but the final calculation involves subtracting the combined result from 999 (e.g., 999 - (176 + 746) = 77), and the answer is interpreted as a negative value, such as -77.
The same complement principle is used for binary numbers, simplifying the process with the 'ones' complement'. The ones' complement is generated by merely inverting all bits of a binary number (0s become 1s, and 1s become 0s), also referred to as negation or inverse. For an 8-bit example like 253 - 176 (binary 11111101 - 10110000), the ones' complement of the subtrahend (10110000) is 01001111. This complement is added to the minuend (11111101 + 01001111 = 101001100). Then, 1 is added (101001100 + 1 = 101001101), and 100000000 (decimal 256) is effectively subtracted, yielding 01001101, which is decimal 77. For subtractions where the subtrahend is larger, the final step is to subtract the result from a string of 1s (e.g., 11111111), indicating a negative outcome.
📚 Continue Your Learning Journey — No Payment Required
Access the complete Code summary with audio narration, key takeaways, and actionable insights from Charles Petzold.