Offset binary

The excess code is a binary encoding can represent binary with which signed numbers. The coding is based on a range of values ​​shift.

Usually positive numbers in the range 0 to 2n -1 as n- digit binary numbers be coded as follows (in this case for the value range 0 to 7 ):

To enable a binary representation of negative numbers, here, the value range of the numbers is moved. The length of the shift is for N> 0 is always a power of 2 N -1. It is therefore also called an excess -N code. The excess -0 encoding is the default encoding.

In the following, all possible excess -N codes for binary three-digit numbers are given. The code itself remains the same for all N, only the corresponding numbers are changing.

Of particular importance is the excess -n- code ( ie N = n, in the example: Excess -3). He divides the value range of numbers into two equal halves of negative and positive numbers (if one conceives the 0 as a positive number ). With binary four -digit code ( decimal 0 to 15 ) of the excess - 4 code would thus represent the numbers from -8 to 7, with five-digit codes, it would be the excess - 5 code and the values ​​range from -16 to 15 is referred to in case N = n also short of the excess coding, allows the numerical value N so away.

In order to encode a number A, to choose the smallest number within the value range, and b forms the difference d = | a - b |. Then the result is coded as usual.

Conversely, it decodes a coded number of excess N-, by first converting it according to the usual coding in a number and then adds the minimum number of the range.

Calculation example

Task: Encode the number -79 in the excess -8 encoding

The code length is n = 8 therefore applies to the usual binary representation:

000000002 = 010 and

111111112 = 25510 Since the number is to be excess - 8 encoded, the range of values ​​shifts to:

00000000Exzess -8 = -12 810 or

11111111Exzess -8 = 12710 coding:

The number to be coded is a = -79. The smallest number in the range b = -128 The difference is d = | -79 - (-128 ) | = 49 The default encoding is d = 4910 = 001 100 012 Thus, the solution is a = -7910 = 00110001Exzess -8

The decoding is analogous: 00110001 can be determined by the default encoding to decode 49. After that, the smallest number of the range is added, here -128, ie: 49 - 128 = -79.

Application

Excess code is tolerant of binary addition / subtraction and lexical size comparison. In the IEEE 754 standard for the representation of floating-point exponent is encoded in an excess code - like form. Integer values ​​are, however, mostly processed in the arithmetic unit of modern hardware in two's.

323299
de