Joe Pfeiffer
6/9/2011 8:04:00 PM
Keith Thompson <kst-u@mib.org> writes:
> Roberto Waltman <usenet@rwaltman.com> writes:
>>> Keith Thompson wrote:
>>>> A 2's-complement representation makes some operations easier,
>>
>>>And some harder.
>>
>> Could you expand this? What operations are easier using other
>> representations? (Other than BCD, etc. for financial applications.)
>
> The most obvious example is negation. In sign and magnitude, you
> just invert the sign bit. In ones' complement, you invert every bit.
> In two's complement, you invert every bit and then increment (which
> can toggle every bit again).
A 2's complement carry-lookahead adder takes half the carry logic of a
1's complement (because the 1's complement has a wrap-around carry).
A sign-magnitude adder is a mess, since you have to compare the signs on
the inputs to decide whether you're going to add vs. subtract, and
compare magnitudes to decide which one you subtract from the other.
By the time you've got the hardware on hand to both add and subtract,
being able to invert a number doesn't take any new hardware to speak of.
> This assumes that he difficulty of an operation is measured by the
> number of bits that are affected, which probably isn't the case.