Why do we perform subtraction using compliment rather than direct subtraction?
Answers
Answer:
Subtraction is done by adding the ten's complement of the subtrahend, which is the nines' complement plus 1. The result of this addition used when it is clear that the difference will be positive, otherwise the ten's complement of the addition's result is used with it marked as negative
Explanation:
You need some way to represent a negative number. You could have a computer that didn’t do negative numbers but it wouldn’t be very useful.
Given that you need a way to represent negative numbers, you need to decide how you’re doing to do it. For example you can make the number half-way up be zero. So, for example with 8-bit numbers, 10000000 would be zero. That’s called excess-128 format.
But it’s very useful to have 00000000 be zero, because that’s easily recognisable by both humans and computers. It also means that you can use the same instructions to recognise a zero value in a signed or unsigned number.
One other way you can do it is to have the top bit be the sign. So 10000001 is -1. The problem with that is that both 10000000 and 00000000 are zero. That’s awkward to handle.
After that, people tried one’s complement. That’s just inverting all the bits for a negative number. But that also has two zeros: 00000000 and 11111111.
Almost all computers now use two’s complement because it’s the easiest to build into hardware — it just works. Also it has one zero and it’s 00000000.
The other formats are used in computers. With floating point numbers, other considerations have more weight and that changes which format is the best. Invariably, the mantissa is held in sign-and-magnitude format and the exponent is in excess-N format.
Whichever format you choose, the computer hardware has to be able to subtract numbers. It just turns out to be simpler hardware if you use two’s complement.
Answer:
ou need some way to represent a negative number. You could have a computer that didn’t do negative numbers but it wouldn’t be very useful.
Given that you need a way to represent negative numbers, you need to decide how you’re doing to do it. For example you can make the number half-way up be zero. So, for example with 8-bit numbers, 10000000 would be zero. That’s called excess-128 format.
But it’s very useful to have 00000000 be zero, because that’s easily recognisable by both humans and computers. It also means that you can use the same instructions to recognise a zero value in a signed or unsigned number.
One other way you can do it is to have the top bit be the sign. So 10000001 is -1. The problem with that is that both 10000000 and 00000000 are zero. That’s awkward to handle.
After that, people tried one’s complement. That’s just inverting all the bits for a negative number. But that also has two zeros: 00000000 and 11111111.
Almost all computers now use two’s complement because it’s the easiest to build into hardware — it just works. Also it has one zero and it’s 00000000.
The other formats are used in computers. With floating point numbers, other considerations have more weight and that changes which format is the best. Invariably, the mantissa is held in sign-and-magnitude format and the exponent is in excess-N format.
Whichever format you choose, the computer hardware has to be able to subtract numbers. It just turns out to be simpler hardware if you use two’s complement.