Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

they'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.



Did 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.


That is exactly the 9‘s complement. The digits add up to 9.


I 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.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: