Re:Finally Getting Two's Complement
by hammock on Saturday June 24, 2023 @10:22AM
(#36458917)
This explanation has made me realize i can’t remember the last time I tried to substract two four digits numbers without a calculator. I’m not even sure I know how
[ Parent
| on HN ]
In case you're serious, just go right to left, digit by digit.
7 - 3 = 4:
8 4 6 7
- 4 5 8 3
-------------
4
6 is less than 8, so borrow from the next digit. 16 - 8 = 8: 8 3 16 7
- 4 5 8 3
-------------
8 4
3 is less than 5 so borrow from the next digit. 13 - 5 = 8: 7 13 16 7
- 4 5 8 3
-------------
8 8 4
7 - 4 = 3: 7 13 16 7
- 4 5 8 3
-------------
3 8 8 4
And there's the answer!I guess that’s how I would attempt it if I had to- reverse of addition. Just can’t remember when I have had to. Funny how addition and subtraction are unequally distributed in life
Interesting cultural differences here: the way I learned it, you increment the next digit of the subtrahend (the lower number) on digit underflow, rather than borrowing from the next digit in the minuend. (So it's rather a carry than borrowing.) Anyways, explicit borrow does for a nice explanation.
That is interesting! I could see that make learning it easier since it's closer to addition if you carry instead of borrow. Though one advantage I see to the borrow is, since you're modifying the minuend, you have room to write the modified value of the digit directly above itself.