Skip to content

Excess

This last common representation tries to mitigate the jump from largest number to the smallest number when we increment by one. The problem with the jump is comparing two numbers requires additional check. Consider comparing 7, 3, -2 and -4 in a 4-bit numbers.

Number Sign-and-Magnitude 1s Complement 2s Complement
7 0111 0111 0111
3 0011 0011 0011
-2 1010 1101 1110
-4 1100 1011 1100

How would we compare two numbers in different representation? The easiest will be comparing two positive numbers. In such cases, we simply compare the binary representation.

Next, consider comparing positive and negative number. To find the larger number, we simply have to check the first bit and ignore the rest. Now, for the real problem. When we compare two negative numbers like -2 and -4, it is not enough to just ignore the first bit and compare the rest of the bits:

  • Sign-and-Magnitude: The larger number is number where the rest of the bits is smaller as it corresponds to the magnitude.
  • 1s Complement & 2s Complement: The larger number is the number where the rest of the bits is larger.

So now, we have a rather complex operations involving selections to check if a number A is smaller than number B. The pseudo-codes for each representation is written below. Here, we use a Pythonic notation where A[0] is the left-most bit and A[1:] is the rest of the bits.

Sign-and-Magnitude Comparison
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# input : number A in sign-and-magnitude
#         number B in sign-and-magnitude
# output: Boolean C = A < B
if A[0] == B[0] then  # equal sign
  if A[0] == 0 then   # positive
    C = A < B
  else                # negative
    C = A[1:] > B[1:]
  end
else
  C = A[0] < B[0]
end
1s Complement Comparison
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# input : number A in 1s complement
#         number B in 1s complement
# output: Boolean C = A < B
if A[0] == B[0] then  # equal sign
  if A[0] == 0 then   # positive
    C = A < B
  else                # negative
    C = A[1:] < B[1:]
  end
else
  C = A[0] < B[0]
end
2s Complement Comparison
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# input : number A in 2s complement
#         number B in 2s complement
# output: Boolean C = A < B
if A[0] == B[0] then  # equal sign
  if A[0] == 0 then   # positive
    C = A < B
  else                # negative
    C = A[1:] < B[1:]
  end
else
  C = A[0] < B[0]
end

The next representation we are discussing is solving this exact problem. In particular, we will remove the need for selection statement to compare two numbers. Consider the cause of this problem. The root cause is that when we keep on incrementing the binary representation by 1, there is a discontinuity in the decimal value.

Discontinuity

In the case of 4 bit numbers:

  • Sign-and-Magnitude: Jump from +7 (or (0111)sm) to -0 (or (1000)sm)
  • 1s Complement: Jump from +7 (or (0111)1s) to -7 (or (1000)1s)
  • 2s Complement: Jump from +7 (or (0111)2s) to -8 (or (1000)2s)

To remove this discontinuity, we simply state we do not start counting from 0 but instead, count from some number N. In other words, given a sequence of bits, we simply convert it into decimal and then add/subtract some value according to the starting number N.

Representation

Excess representation requires two values, the starting number and the number of bits. We then let the representation 000...00 to represent the starting number.

However, the naming convention can be rather weird. Let's illustrate this with a concrete example. Consider the following number:

  • Starting number is -4
  • Number of bits is 3

We call this representation Excess-4 representation on 3-bit numbers. The numbers are listed below.

Excess-4 Value Excess-4 Value
000 -4 100 0
001 -3 101 1
010 -2 110 2
011 -1 111 3

In general, if we have Excess-N on M-bit numbers, we have:

  • Starting number is -N
  • Number of bits is M
Quick Quiz
  1. What if we use Excess-2 on 3-bit numbers?
  2. What if we use Excess-7 on 3-bit numbers?
  1. Excess-2 on 3-bit

    Excess-2 Value Excess-2 Value
    000 -2 100 2
    001 -1 101 3
    010 0 110 4
    011 1 111 5
  2. Excess-7 on 3-bit

    Excess-7 Value Excess-7 Value
    000 -7 100 -3
    001 -6 101 -2
    010 -5 110 -1
    011 -4 111 0

Properties

Range

Ideally, we want the number to be evenly distributed between positive and negative value. We can do this by starting from the default range between 0 and 2n-1. Then we translate the value so that the starting number is not 0. The translation can be done by either addition/subtraction.

Using a simple calculation, to make it evenly distributed, we simply halve the largest value. So, instead of 2n-1, we should have 2n-1-11. Hence, the smallest number should be -2n-1.

As we have seen from the case of Excess-4 on 3-bit numbers above, we get a roughly equal number of positive and negative. The number 4 was chosen by the calculation. Since the smallest number is -2n-1 = -23-1 = -22 = -4, the representation should be Excess-4. Uneven distribution may be used but it is uncommon.

Quick Quiz

To ensure even distribution, what should be the value of N in Excess-N for the following number of bits?

  1. 8-bit
  2. 11-bit
  3. 16-bit
  1. Excess-128 or Excess-127

    Working

    2n-1 = 28-1 = 27 = 128

    OR

    2n-1-1 = 28-1-1 = 27-1 = 128-1 = 127

  2. Excess-1024 or Excess-1023

    Working

    2n-1 = 211-1 = 210 = 1024

    OR

    2n-1-1 = 211-1-1 = 210-1 = 1024-1 = 1023

  3. Excess-32768 or Excess-32767

    Working

    2n-1 = 216-1 = 215 = 32768

    OR

    2n-1-1 = 216-1-1 = 215-1 = 32768-1 = 32767

Arithmetic

Unfortunately, addition is not as simple as binary addition. To illustrate, consider adding -4 + -3 for Excess-4 on 3-bit numbers.

1
2
3
4
000
001
--- +
001

Clearly, it is wrong. The advantage of Excess-N representation is really just comparing two numbers. In this case, comparing two Excess-N numbers is really just comparing their binary representation directly as if they are decimal values. This can be directly inferred from the fact that Excess-N numbers are just translation of binary numbers (i.e., shifted by additiong/subtraction).

4 bit Excess-N

To ensure even distribution between positive and negative numbers, we can either choose Excess-7 or Excess-8 representation. The most common one is Excess-8.

Excess-8 Value Excess-8 Value
0000 -8 1000 0
0001 -7 1001 1
0010 -6 1010 2
0011 -5 1011 3
0100 -4 1100 4
0101 -3 1101 5
0110 -2 1110 6
0111 -1 1111 7
Excess-7 Value Excess-7 Value
0000 -7 1000 1
0001 -6 1001 2
0010 -5 1010 3
0011 -4 1011 4
0100 -3 1100 5
0101 -2 1101 6
0110 -1 1110 7
0111 0 1111 8

?? info "Floating Point" The number 7 can be computed from 2n-1-1 instead of 2n-1. This favours positive numbers more than negative numbers. IEEE floating point standards uses the former method of 2n-1-1 instead of the latter method 2n-1 for the exponent.


  1. It's usually okay to have an off-by-one error where the largest value is 2n-1. To be fair we cannot have exactly equal number of positive and negative because 0 is neither. Just note that the calculation we have done is based on the most common convention called Excess-2n-1 representation.