Negative numbers represent values less than zero. Everyone knows that. However, negative
numbers are a rather modern concept, because the concept of a negative value is not
intuitive. You can have five apples, but what of -
Negative numbers are used to represent values that are less than the zero datum;
for example, if sea level is zero, then -
If I say I have -
Historically, negative numbers were developed I(in Europe) in response to the solutions of equations whose roots were negative.
We represent a negative number by prefixing it with a negative sign; for example,
Representing Negative Binary Integers
Suppose we use four bits to represent an integer. This gives us the range 0000 to 1111 (or 0 to 15 decimal). How can we represent negative values?
We can’t use a minus sign because that would be quite meaningless. What we can do
is to reserve the most-
0 000 0
0 001 1
0 010 2
0 011 3
0 100 4
0 101 5
0 110 6
0 111 7
1 000 -
1 001 -
1 010 -
1 011 -
1 100 -
1 101 -
1 110 -
1 111 -
The range of numbers is -
This is the sign and magnitude representation of signed numbers and it corresponds
to the way people handle negative numbers; that is, the most-
An alternative technique avoids negative numbers altogether by adding a constant to all numbers so that they are all greater than zero. Consider the previous example with four bits where we add 8 to each number; that is
0 0 + 8 = 8 1000
1 1 + 8 = 9 1001
2 2 + 8 = 10 1010
3 3 + 8 = 11 1011
4 4 + 8 = 12 1100
5 5 + 8 = 13 1101
6 6 + 8 = 14 1110
7 7 + 8 = 15 1111
In this case we have a range of binary values 0000 to 1111 that correspond to the
range 0 to 15 or -
This mechanism is called biased because each number is represented by a value biased by the addition of a constant. In this case, the bias is 8. Note that it is also called excess n notation where n is the value of the bias.
The biased representation of numbers has three advantages; first, there is only one
value for 0. Second, it is monotonic because the relative ordering of both the binary
integer representation and the biased representation is the same; for example, 0110
is smaller than 1001 irrespective of whether these are unsigned integers or biased
values. Finally, the most-
The biased representation does have one disadvantage. Consider the addition of -
This gives a result with a carry out of 16 and the remainder 0100 which is -
If we consider the numbers as X and Y we added their biased forms (X + 8) + (Y + 8) = X + Y + 16. If We require the answer in biased form; that is, X+Y + 8; We ended up with an extra 8. TO demonstrate this, we will subtract 8 from the result we achieved; that is
The answer 1100, when interpreted in biased form is 4, which is what we were expecting. It is easy to see where we went wrong. Adding together two biased numbers, doubles the bias. We then have to remove one to get the expected answer.
So, the biased representation of signed numbers is not used to represent integers.
However, it is used to represent the exponent of floating-
The system used to university represent signed numbers in integer arithmetic is two’s complement.
Two’s Complement Arithmetic
The two’s complement of a number X is defined as 2n – X, where n is the number of
bits used to represent the number. Consider the two’s complement of 3 in four bits.
This is 24 – 3 = 16 – 3 = 13 = 1101. We represent -
In order to understand the significance of this we need to perform an operation;
for example, perform 7 – 3. We do this by performing the addition 7 + (-
In this example, we get 10100 which is a carry out of 1 and a result of 0100. If we forget the carryout, the result is correct. What happened?
We added the two’s complement of 3 to 7; that is
7 + (24 – 3) = 24 + 7 -
Clearly, adding the two’s complement of a number performs subtraction leaving us with a carry out bit that can be ignored.
Two’s complementary arithmetic works for all combinations of values:
X + Y,
X – Y,
–X – Y.
For example, consider -
Here we get a carry out and 1101. The expected value is -
In four bits, the range of values in two’s complement arithmetic is given by:
The advantages of two’s complement arithmetic are:
The range of values are 2n -
There is only one zero which is represented by 000…0 (all zeroes)
It is very easy to generate two’s complement values: invert the bits and add 1.
The disadvantage of two’s complement arithmetic is that is does not work for multiplication and division. In other words, if you multiple X and –Y you do not get the two’s complement value of –XY. This means that you have to implement two multiplication systems; one for unsigned integers and one for signed integers.
The most important feature of two’s complement arithmetic is that you can form –X without subtraction; that is you do not need subtraction to calculate 2n – X.
An alternative way of forming two’s complement values is to invert the bits and add
1. Consider -
It is important to remember that when using two’s complement arithmetic, you cannot
drop leading zeroes. In 8 bits + 5 is 00000101. You cannot write this as 101 because
you have to include the sign-
We said that a two’s complement value in n bits has the range 2n -
Note that the result is correct if we regard the numbers as unsigned. However, we
are using signed two’s complement arithmetic and the result, 1011 is equal to -
Adding two positive numbers whose total exceeds 7 leads to a negative result. Similarly,
subtracting two negative numbers whose total is more negative than -
Summary of Basic Points
Negative integers can be represented in a signed form by means of two’s complement notation.
The value –X is represented in two’s complement form by 2n – X where n is the number of bits in the number.
A two’s complement value, 2n – X, can be calculated by inverting all the bits of X and adding 1.
If you add two numbers (with negative values in two’s complement form) negative numbers will be automatically subtracted; that is, you do not need to perform subtraction because subtraction is implemented by adding a complement.
A two’s complement value is a true complement in the sense that adding X + (-
The range of possible values of a signed two’s complement value in n bits is 2n
If you add two positive integers or subtract two negative integers and the value of the result is outside the range of values that can be represented, then arithmetic overflow has taken place.
If you extend the number of bits in an n-
Examples of Two’s Complement Problems
1. What is a two’s complement number?
A two’s complement number is a way of representing a negative integer and is defined as 2n – X, where n is the number of bits in the representation and X is the integer.
2. Why are two’s complement numbers used to represent negative integers?
Because adding the two’s complement of X is the same as subtracting X. This means that you do not need both an adder and a subtractor. To add X and Y you present X and Y to an adder. To subtract X form Y you present Y and the two’s complement of X to the same adder.
It is easy to form a two’s complement number by inverting the bits and adding 1.
3. What other systems (conventions) are used to represent negative numbers?
Sign and magnitude representation uses a sign bit to indicate the sign and then the remaining bits represent the number. This form is used only in the representation of floating point values.
Biased numbers or excess numbers add a constant to the number to be represented to ensure that all representations are positive. This mechanism is used only in floating point arithmetic to represent exponents.
4. What is the range of a two’s complement number in 10 bits?
The range of legal two’s complement values in n bits is -
5. How can you tell whether a given binary integer is in a two’s complement or an unsigned integer form?
You can’t. In four bits it is impossible to determine whether 1001 represents +9
(unsigned) or -
6. What is arithmetic overflow?
Arithmetic overflow takes place in two’s complement arithmetic when the result of an operation falls outside the range or representable numbers. Typically, this means that adding two numbers is greater than the maximum, or subtracting two numbers is less than the minimum.
7. A two’s complement integer in 8 bits is 10111000. This value is to be converted
into a 12-
8. In 8-
a. +5 00000101 00000101 No change: positive
9. Convert the following values into binary form and carry out the calculations using two’s complement arithmetic in six bits.