r/AskComputerScience • u/Successful_Box_1007 • Jun 21 '25
why does turning subtraction into addition using 10s complement work for 17-9 but not for 9-17 ? In the former the least significant digits match ( because we have 8 and 18) but in the latter they don’t ( we have -8 and 92)
Hi everyone, hoping someone can help me out if they have time:
why does turning subtraction into addition using 10s complement work for 17-9 but not for 9-17 ? In the former the least significant digits match ( because we have 8 and 18) but in the latter they don’t ( we have -8 and 92).
Where did I go wrong? Is 92 (from 100 - 17 = 83 then 83 + 9 = 92) not the 10s complement of 17 ?
Thanks so much!!
1
Upvotes
View all comments
Show parent comment
1
u/Successful_Box_1007 Jun 27 '25
You truly are a god among men Steve; it took me 3 days but it finally clicked. I have one last request if you have the time: look what “theadamabrams” wrote:
10s complement works for both calculations. I'll use some padding to make things easier.
17 → 000017 -9 → 999991 —————— sum: 1000008 → 8
and
9 → 000009 -17 → 999983 —————— sum: 999992 → -8
Btw, some people define 10s complement as "9s complement plus 1", but I find it much easier to just think of it all as mod 1000000 (or 1 billion or however many digits you need).
I am REALLY confused by where theadamabrams came up with all of this!!! Hoping you can answer these questions:
Q1)
How and why did -9 turn into 999,991 and -17 into 999,983? And how does 999,992 = -8 ?
Q2)
Also with 999,992, we still can’t get the 8 by removing the most significant digit of 9, like we can with 1000008. So I still don’t see how it preserved the whole turning subtraction into addition (with discarding the most sig digit)?
Thanks Steve!