Excess code

from Wikipedia, the free encyclopedia

The offset binary or surplus code is a binary encoding , with which signed numbers in binary can represent. The coding is based on a value range shift.

Usually positive numbers in the value range 0 to 2 n -1 are coded as n-digit binary numbers as follows (here for the value range 0..7; standard coding):

shown in decimal binary mapped
0 000
1 001
2 010
3 011
4th 100
5 101
6th 110
7th 111

In order to enable the binary representation of negative numbers, the range of values ​​of the numbers is shifted. The extent of the shift is normally in the range k = m - p, where m = 2 n-1 and 0 <= p <= m. One therefore speaks of an excess k code. The excess 0 coding corresponds to the standard coding (see above).

The common excess k codes for three-digit binary numbers are given below.

Coding shift code
000 001 010 011 100 101 110 111
Excess 0 0 0 1 2 3 4th 5 6th 7th
Excess-1 1 -1 0 1 2 3 4th 5 6th
Excess-2 2 -2 -1 0 1 2 3 4th 5
Excess 3 3 -3 -2 -1 0 1 2 3 4th
Excess-4 4th -4 -3 -2 -1 0 1 2 3

The next table lists some possible excess k-codes for binary four-digit numbers.

Coding shift code
0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111
Excess 0 0 0 1 2 3 4th 5 6th 7th 8th 9 10 11 12 13 14th 15th
Excess-1 1 -1 0 1 2 3 4th 5 6th 7th 8th 9 10 11 12 13 14th
Excess-2 2 -2 -1 0 1 2 3 4th 5 6th 7th 8th 9 10 11 12 13
Excess 3 3 -3 -2 -1 0 1 2 3 4th 5 6th 7th 8th 9 10 11 12
Excess-4 4th -4 -3 -2 -1 0 1 2 3 4th 5 6th 7th 8th 9 10 11
Excess 8 8th -8th -7 -6 -5 -4 -3 -2 -1 0 1 2 3 4th 5 6th 7th

The (4-bit) excess 3 code , which is identical to the excess 3 in the table above, has historical significance - it offers advantages when it comes to representing and calculating with decimal numbers.

The excess k code has a very important and special value here, which is shifted by eight places in the above example (i.e. generally k = 2 n-1 , in the example: excess-8). It divides the range of values ​​of the numbers into two equal halves of negative and nonnegative numbers. For binary four-digit codes (decimal 0 to 15) the excess 8 code represents the numbers from -8 to 7, for five-digit codes it would be the excess 16 code and the value range from -16 to 15. One speaks in the case k = 2 n-1 also short of excess coding , so omits the numerical value k. For example, when the excess representation is used for the exponent, this balanced excess code (half negative and half non-negative) is meant in almost all cases.

To encode a number a, one chooses the smallest number b in the range of values ​​and forms the difference: d = | a - b |. The result is then coded as usual.

Conversely, you decode an excess k-coded number by first converting it into a number according to the usual coding and then adding the smallest number in the value range.

Calculation example

The following calculation example only deals with the so to speak balanced excess code (this is the case with k = 2 n-1 ), which divides the numbers evenly into negative and nonnegative ones.

Task: For 8 bits, code the number -79 in excess 128 coding

The code length is n = 8; so for the usual binary representation:

000000002 = 010

and

111111112 = 25510

Since the number is to be coded excess 128, the range of values ​​shifts to:

00000000Exzess-128 = -12810

or.

11111111Exzess-128 = +12710

Coding:

Die zu codierende Zahl ist a = -79.
Die kleinste Zahl im Wertebereich ist b = -128
Die Differenz ist d = |-79 - (-128)| = 49
In der Standardcodierung ist d = 4910 = 001100012

So the solution is : a = -79 10 = 00110001 excess-128

The decoding is analogous: 00110001 can be decoded to 49 according to the standard coding. Then the smallest number in the value range is added, here -128, i.e.: 49 - 128 = -79.

application

Excess code is tolerant of binary addition / subtraction and lexical size comparison. In the IEEE-754 standard for representing floating point numbers, the exponent is encoded in a form similar to an excess code. However, integer values ​​are mostly processed in two's complement in the arithmetic unit of modern hardware .

See also

Individual evidence

  1. Excess 8 code is called the offset binary here. See this PDF file.