The essence of ``negativity'' is the notion of negation. The symbol
of negation is a minus sign. In other words, the negation of a value
is
.
can be positive, negative or zero to start with. Let
us take a look at the effects of negation.
The most common notation of negation is the
symbol. In other words,
in
,
is the negation of y, and vice versa. If an operator
fulfills the job of negation, then
and
.
In our usual ``people'' math, negation is simple: we just prefix the
value being negated by a
symbol. In a computer, however, negation is
a little more complicated. This is because the memory of a computer
can only represent zeros and ones. There is no provision to represent
the negation operator.
Fortunately, there is a quick-and-easy method to represent negative
numbers and negate numbers. This method is called ``two's complement''.
We'll use
to represent the two's complement of
. If there
is an operation called two's complement, there must be an operation
called one's complement. We'll use
to represent the one's
complement of
.
For one's complement and two's complement, it is important that we fix the number of digits being considered. Let us assume from now on that our binary numbers have exactly 8 bits.
One's complement is an operation to ``flip'' each binary digit of a
number. For example,
. One's complement
is meaningful only to binary representations.
Two's complement depends on one's complement. The definition of two's complement is as follows:
| (8.21) |
This means we can compute the two's complement of
as follows:
| (8.22) | |||
| (8.23) | |||
| (8.24) |
Now, let us test some of the properties of two's complement and see if it fits as a negation operator.
First, let's check if
.
| (8.25) | |||
| (8.26) | |||
| (8.27) |
Next, we check if
:
| (8.28) | |||
| (8.29) |
Note that although the result is
, because we restrict
ourselves to the least significant 8 digits, the answer is
.
Although none of this is any formal proof that two's complement can be used as negation for binary presentations, we did demonstrate that two's complement has some of the properties of negation.
Our current question is, then, which one is positive and which one
is negative? In our example, does
represent a positive
quantity, or does
represent this quantity?
The rule to determine the sign (negative or otherwise) is that if the
most significant bit is a one, the number represents a negative value.
Using this rule,
is non-negative because the most significant
bit (leftmost) is zero.
, on the other hand, represents
a negative value.
Our next question is, what is the value represented by
?
For non-negative values, we can directly apply the method as
discussed in section 8.1.2.
. Because
represents the
negation of this value, it represents
.