Re: one's compliment operator



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.
.



Relevant Pages

  • Re: Well Ordering the Reals
    ... >>> If you do not specify the number of bits, then you don't know what number ... >>> number in order to compare it with another number. ... A TO-number starting with a zero and having infinitely many zeros ... So how does one tell, strictly from their representations, which is ...
    (sci.math)
  • Re: array elements
    ... They will all compare equal to zero but need not be represented by all ... one of the many valid representations ... The point I was trying to make is that the default initialization for ... a static object is performed more in the manner of an assignment ...
    (comp.lang.c)
  • Re: How are JS numbers represented internally? v.2
    ... results with numbers that would have exponented string ... as - parseInt - produces. ... What happens around zero is much more significant. ... delusions about the representations of numbers on computer systems in ...
    (comp.lang.javascript)
  • Re: I dont get how the computer arrives at 2^31
    ... > No, the value zero can have multiple representations, and nothing ... Note that a minus zero rep. will not normally ... A comparison such as x==0 is required to yield true if x has any ... The obvious way to do this is to canonicalize x and do a bitwise ...
    (comp.std.c)
  • Re: t1lib, %SYSTEM-F-HPARITH
    ... (Not all bit representations ... >are valid floating-point numbers.) ... Zero is represented by all-zeroes. ... especially if the exponent is not offset as Vax ones are. ...
    (comp.os.vms)