next up previous contents
Next: Range of Values Up: Binary Numbers Previous: Multiplication   Contents


Negative Values and Negation

Up to this point, we have only discussed positive integers (represented in base-2). A computer needs to store and process negative values as well. We need a method to represent negative values. Before we discuss the actual method, let's think about what a negative number is.

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 $x$ is $-x$. $x$ 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 $x=-y$, $x$ is the negation of y, and vice versa. If an operator fulfills the job of negation, then $x = -(-(x))$ and $x+(-x)=0$.

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 $C_2(x)$ to represent the two's complement of $x$. If there is an operation called two's complement, there must be an operation called one's complement. We'll use $C_1(x)$ to represent the one's complement of $x$.

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, $C_1(01101101_2)=10010010_2$. 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:


\begin{displaymath}
C_2(x)=C_1(x)+1
\end{displaymath} (8.21)

This means we can compute the two's complement of $01101101_2$ as follows:


$\displaystyle C_2(01101101_2)$ $\textstyle =$ $\displaystyle C_1(01101101_2)+1$ (8.22)
  $\textstyle =$ $\displaystyle 10010010_2 + 1$ (8.23)
  $\textstyle =$ $\displaystyle 10010011_2$ (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 $x=C_2(C_2(x))$.


$\displaystyle C_2(C_2(01101101_2))$ $\textstyle =$ $\displaystyle C_2(10010011_2)$ (8.25)
  $\textstyle =$ $\displaystyle 01101100_2 + 1$ (8.26)
  $\textstyle =$ $\displaystyle 01101101_2$ (8.27)

Next, we check if $x+C_2(x) = 0$:


$\displaystyle 01101101_2 + C_2(01101101_2)$ $\textstyle =$ $\displaystyle 01101101_2 + 10010011_2$ (8.28)
  $\textstyle =$ $\displaystyle (1)00000000_2$ (8.29)

Note that although the result is $100000000_2$, because we restrict ourselves to the least significant 8 digits, the answer is $00000000_2$.

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 $01101101_2$ represent a positive quantity, or does $10010011_2$ 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, $01101101_2$ is non-negative because the most significant bit (leftmost) is zero. $10010011_2$, on the other hand, represents a negative value.

Our next question is, what is the value represented by $01101101_2$? For non-negative values, we can directly apply the method as discussed in section 8.1.2. $01101101_2=64+32+8+4+1=109$. Because $10010011_2$ represents the negation of this value, it represents $-109$.


next up previous contents
Next: Range of Values Up: Binary Numbers Previous: Multiplication   Contents
Tak Auyeung 2003-12-03