I've programmed on systems using "one's complement" binary, and
also the much more common "two's complement" representation.
My only question is, where do those two names come from--and is
there any logic behind them which would help a person to remember
which is which?
Thanks!
(For onlookers: in one's complement binary, the representation of
negative numbers is the exact inverse of the corresponding positive
number. For example, binary 011011 == decimal 27; the one's
complement representation of negative 27 would thus be 100100.)
(The problem with that approach is that it creates both a "positive"
and a "negative" representation for the single value "zero.")
(In two's complement binary, negative integers are tweaked so that
a "negative zero" doesn't exist. Going back to the example of 27,
the two's complement representation for negative 27 would be
100101 rather than 100100. This is the system used on most modern
microprocessors.)
Easier to remember is the one's complement, which came from the fact that
if you change every 0 to 1 and vice versa, that was in effect just like
subtracting the number from all ones.
example:
-27 = 100100 = 111111 - 011011
= 111111 - 27
Hope that helps.:)
--Salarius
David Satz <DS...@msn.com> wrote in article
<ue8znVQ...@upnetnews02.moswest.msn.net>...
--
They wait apart in waning day, |meow I don't use no smilies.
the flare of crimson fades to gray. | smj...@my-dejanews.com
They rest their violence, the rest is silence.| www.geocities.com
Their empty years are ash and clay. | /SoHo/Studios/5079/index.html
The one's complement is simple - all bits are inverted (complemented). The
two's complement is arrived at by taking the one's complement and adding
(binary) 1 to the result. So: The two's complement is 1 more than the one's
complement, or
2's complement = 1's complement + 1
The ones complement is just a matter of inverting each bit.
Imagine that a word is represented as sbbbbbbbbbbbbbbbbb, where s is the
sign bit, and each b is a data bit. Imagine also that a radix point is
implicitly located between the s and the first b. The twos complement of a
number "n" is "2-n", with "2" being represented by a bunch of zero bits with
a "1" bit to the left of the sign bit.
Ken Salter