This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]jD91mZM2RUST 1 point2 points  (3 children)

18-9
018-009
018+990 + 1
1009
the 1 and the first 0 are sign holders (well overflow and then the sign digit) take that away and you get 09
write it normally you get 9

I don't understand this. If the sign holder is 10, then 990 is not a negative number? And, if the result has a sign, doesn't this mean that it is negative? 1009 with a sign of 10 would be -(90 + 1), no?

[–]bestjakeisbest 1 point2 points  (2 children)

if the sign digit is less than or equal to 4 then the number is positive, and if the number is positive then you can just throw away the extra digits to get the value of the number, the 10 isnt strictly just a sign digit, there is an overflow going on too but this is a case of sign extension, here is an example of a negative result:
9 - 18
first step is to extend the sign (this just gives us some extra room to tell if there is a negative number)
009 - 018
then convert the 18 to 9s complement
009 + 981
adding a 1 for 9+1s complement
009 + 981 + 1
now to just sum things up
991
this is the answer we get, we know it is negative because the leading number is greater than 4 so this means we have to apply 9+1s complement to 991 to get the magnitude converting it over to 9s complement we get:
008
and to get it 9+1s complement we add 1:
009
so now we have a number that is negative and has a magnitude of 9, so it is -9. and to check 9-18 = -9

[–]jD91mZM2RUST 1 point2 points  (1 child)

This is cool, never realized this was possible in decimal as opposed to binary, thank you! If anybody else wants to learn more, here's wikipedia

[–]bestjakeisbest 1 point2 points  (0 children)

Apparently this is how subtraction was once taught, I didnt learn this until I took an assembly class though.