5 ms·
> Let's say you need to calculate 8467 - 4583 > The ten's complement of 4583 is 5417 It looks like here you are calculating 9999 - 4583 = 5416 (an easy subtra
by tuukkah 3y ago
> Let's say you need to calculate 8467 - 4583
> The ten's complement of 4583 is 5417
It looks like here you are calculating 9999 - 4583 = 5416 (an easy subtraction), then adding one.
> (the complement is the remainder to the next power of ten, in that case to 10000)
Is remainder a correct term here? It's confusing because if you divide 4583/10000, the remainder is 4583. Modulo of -4583 by 10000 is 5417 though.
> This is much easier to calculate than the direct subtraction.
This is not clear to me. Is it because when you calculate 9999-yyyy, you never need to borrow? Or when you calculate 10000-yyyy, you always make a simple borrow? In any case, I feel this still takes some practise because what was a single subtraction becomes two or more steps.
Direct subtraction with paper and pencil isn't much more difficult than direct addition anyway. If you want to do it in your head, I'd prefer a single-step method instead of having to remember the intermediate results.
- IIAOPSW 3y agoImagine you're doing your math on a car odometer that only goes up to 4 digits. When you reach 10k it wraps around. For any X it is easy to find the complement ~X because you can just map the digits independently (0,1,2,3,4 -> 9,8,7,6,5 and vice versa) then adding 1. By construction each digit in X + (~X-1) will be 9, then adding the 1 back in brings it to 10000, which in odometer math wraps around to 0. So ~X is the additive inverse of X meaning that adding ~X always brings you to the same number as subtracting -X. Or think of a clock. Subtracting X hours is always the same as adding (12-X) hours. Or any circle, turning counterclockwise X degrees is always the same as turning clockwise (360-X) degrees. The trick is being able to take the compliment digit-wise in order to replace a subtraction with an addition. In binary this is just flipping 0 to 1 and vice versa. In base 10 you just need to remember 5 pairs of digits to switch out with each other.
- skeeter2020 3y agothey've actually combined some of the steps which might make it easier to understand. It's important that we keep in mind we have 4 digits. 8467 - 4583 = 8467 + 5416 (9's complement of 4583) = 13883 + 1 (10's complement) = 13884 - 10000 = 3884 >> Direct subtraction with paper and pencil isn't much more difficult than direct addition anyway. If you want to do it in your head, I'd prefer a single-step method instead of having to remember the intermediate results. This isn't really a technique for humans, but computers. You can implement add with carry pretty easily with a bunch of logic gates, but what about subtraction where you need to jump across several columns to borrow, keeping track across the entire minuend? Computers don't typically have those little tick marks beside each digit, or scrap paper. It is easy to set a "subtracting" flag though, and invert the subtrahend (1's compliment), and then feed the first carry-in of the ALU with the same signal as the subtract flag (add 1 for 2's complement). You could come up with your own complete subtraction logic, but it's definitely easier to use the same core addition with a tiny bit of extra to handle subtraction and then use a method like this.
- venusenvy47 3y agoDid you calculate the 9's complement of 4583 in your head? I see that 5416 has individual digits that line up with 4583 to each equal 9, but I'm not clear if this is a coincidence that happens to work for this number, or if this is the way to calculate an arbitrary N's complement value.
- Lukas_Skywalker 3y agoThat is exactly the 9‘s complement. The digits add up to 9.
- venusenvy47 3y agoI thought there was more to the calculation of N's complement. Something about adding one to the result. It doesn't seem like something you can easily perform using inspection.