Re: one's compliment operator
- From: richard@xxxxxxxxxxxxxxx (Richard Tobin)
- Date: 16 Jul 2008 16:01:31 GMT
In article <lnhcapzvzd.fsf@xxxxxxxxxxxxxxx>,
Keith Thompson <kst-u@xxxxxxx> wrote:
It turns out that two's complement has considerable advantages over
the other representations. For one thing, it doesn't have two
different representations for zero; if you negate 0, you just get 0
again. The other representations both have distinct representations
for +0 and -0, which means you have to decide how to deal with them.
(Are +0 and -0 equal? If so, you can't compare two numbers just by
comparing all the bits.) Also, if you ignore overflow/wraparound,
many signed and unsigned operations are identical.
The most compelling reason is that it's just what you get if you apply
the usual algorithms for positive numbers even when the result might
be negative. You don't need to do anything special about negative
numbers at all.
Try it in base ten: subtract one from zero. 0 - 1 you can't do, so borrow
10. 10 - 1 is 9. Continue for however many digits you're using, and you'll
find 0 - 1 is 999...999. You're using ten's complement.
So to turn Keith's last sentence around, it's not that you find that
signed and unsigned operations are identical, it's that when you apply
operations without considering sign you find that you have invented a
consistent way of representing negative numbers.
-- Richard
--
Please remember to mention me / in tapes you leave behind.
.
- References:
- one's compliment operator
- From: deepak
- Re: one's compliment operator
- From: Gordon Burditt
- Re: one's compliment operator
- From: deepak
- Re: one's compliment operator
- From: Keith Thompson
- one's compliment operator
- Prev by Date: Re: compiling error
- Next by Date: Re: compiling error
- Previous by thread: Re: one's compliment operator
- Next by thread: Re: one's compliment operator
- Index(es):
Relevant Pages
|