Sei sulla pagina 1di 8

Binary Coded Decimal codes (BCD codes)

A Binary Coded Decimal (BCD) code is referred to as a method of representing decimal digits by means of
binary digits, so that to each decimal digit a specific binary combination is associated and a decimal number
is written by a concatenation process of the binary combinations.

As the decimal alphabet contains ten different digits the minimum number of bits required for the
codification of decimal digits is 4 (n=log2|10|=4). But with 4 bits we can form 16 different combinations of
which only 10 are used. Each code has 4 bits and these can be arranged in any way to represent the decimal
digits. Therefore, even for an n=4 there are many BCD codes which are generated by the following two
selection criteria:
1. the actual binary combinations chosen from the set of 16 combinations;
2. the rule of assignment of these chosen combinations to different decimal digits.

Anyhow, this great number is substantially enlarged by the fact that for the error detection and error
correction principles it is recommended to use a greater number of bits for encoding the decimal digits.

The properties of BCD codes define different classification criteria.

1. A BCD code is called weighted if a weight is associated with each binary digit position and the weighted
sum gives the encoded decimal digit. In general, if weights w1w2w3w4 are associated to the bits b1b2b3b4 we
4
may find the decimal digit d which is encoded by the code word b1b2b3b4 by evaluating d = ∑ bi wi .
i =1
One of the most popular weighted codes is named 8421 BCD code in which the weights are successive
powers of 2 and these powers give the name of the BCD code.

DIGIT 8 4 2 1
N b4 b3 b2 b1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 0 1 0 1
6 0 1 1 0
7 0 1 1 1
8 1 0 0 0
9 1 0 0 1

Let us take the binary combination (word) for digit 6:


6 – 0110
By calculating the weighted sum, we get:
d = 0x8 + 1x4 + 1x2 + 0x1 = 6

All BCD codes are divided into two categories:


1. Weighted BCD codes (W)
2. Unweighted BCD codes (UW)

1
All weighted BCD codes are identified by the pattern of weights (8421, 2421, 7421, etc).

Example:
DIGIT 7421 2421 4221
0 0000 0000 0000
1 0001 0001 0001
2 0010 0010 0010
3 0011 0011 0011
4 0100 0100 0110
5 0101 1011 1001
6 0110 1100 1100
7 1000 1101 1101
8 1001 1110 1110
9 1010 1111 1111

The code 7421 is famous due to the small number of 1’s which are used in all combinations.

The code 8421 coincides with the binary natural code from 0 up to 9.

A decimal number is written by the concatenation of the corresponding groups of 4 bits.

Example:
Let us consider the 8421 BCD code. The decimal number 729 will be represented as a concatenation of 3
groups of 4 bits each:

N10 = 729 – (0111)(0010)(1001)

May different weighted codes are possible but the weights must be chosen in such a way that their sum is not
greater than 15 and not less than 9. Moreover, one of the weights must be 1 and another weight must be
either 1 ad 2.

2. Some of the weighted BCD codes employ only positive weights, while the other BCD codes employ both
negative weighs and positive weights. In case of the negative weights the restriction mentioned above is
relaxed. The weighted positions are marked in case of negative weights by over-bared digits.

Example: the BCD code 8 4 2 1


DIGIT 8 4 2 1
N b4 b3 b2 b1
0 0 0 0 0
1 0 1 1 1
2 0 1 1 0
3 0 1 0 1
4 0 1 0 0
5 1 0 1 1
6 1 0 1 0
7 1 0 0 1
8 1 0 0 0
9 1 1 1 1

2
From the sign of the weights point of view all BCD codes are divided into two classes:
1. BCD codes with positive weights
2. BCD codes with positive and negative weights

Definition:
A BCD code is called self-complemented if by complementing each bit of a code word it
is obtained another code word which corresponds to the 9’s complement of the initial
decimal digit.

Definition:
If D is a decimal digit then the 9’s complement is given by the difference D = 9 − D .

We can form the following pairs of complemented numbers (0,9), (1,8), (2,7), (3,6), (4,5). In other words, for
such codes it is possible to obtain the 9’s complement of an encoded digit by extracting the 1’s complement
of the code word. Such codes are very useful in case of negative decimal number representations and for
simplification of the decimal arithmetic employing negative numbers.

Example:

Let us consider the following weighted BCD code, named 4311 BCD code.

DIGIT 4311
0 0000
1 0001
2 0011
3 0100
4 0101
5 1010
6 1011
7 1100
8 1110
9 1111

Let 0100 be the code word associated to the digit 3. The binary complement of the code word is 1011, which
corresponds to the digit 6. But the 9’s complement of 3 is 6, as
3 = 9−3 = 6
3 ↔ 6 → 0100 ↔ 1011

In the examples given previously we had other self-complemented BCD codes, like 2421 and 4221 (there are
possible several variants of 2421 and 4221 codes, but we shall select only that variant corresponding to the
self-complemented code).

A self-complemented code may be detected by comparing pair-wise combinations which are symmetric to
the center of the table which must be binary complemented.

Property. Any BCD code which is weighted and the sum of the weighs is 9 generates a self-complemented
code.

From this point of view all BCD codes are divided in two classes:
3
1. Self complemented BCD codes
2. Non self complemented BCD codes

4. Any BCD code, if not identified by its weights, it must be identified by a key permitting an easy
identification of the code. Sometimes, the key offers a formula for calculation of the decimal digits.

Example:

The Excess 3 BCD code is a 4 bit BCD code with the column identification b3b2b1b0 where the value of the
coded digit is calculated with the formula:

N = 8xb3 + 4xb2 + 2xb1 + 1xb0 - 3

The Excess 6 BCD code is a 4 bit BCD code where the value of the coded digit is calculated with the
formula:

N = 8xb3 + 4xb2 + 2xb1 + 1xb0 - 6

A simple interpretation for Excess 3 BCD code is that: for representing the digit D we are taking the natural
binary equivalent of D+3.
In case of Excess 6 BCD code, for the digit D we are taking the natural binary representation for D+6.

DIGIT Excess 3 Excess 6


0 0011 0110
1 0100 0111
2 0101 1000
3 0110 1001
4 0111 1010
5 1000 1011
6 1001 1100
7 1010 1101
8 1011 1110
9 1100 1111

5. Another important property is called the additive property. A BCD code is additive if by performing a
binary addition on two code words the obtained sum directly corresponds to the decimal sum of the original
encoded digits. Therefore we can achieve decimal addition by performing a binary addition.

Example: Let us consider the 8421 BCD code.


DIGIT 8421
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
4
If analyzing the sum of two digits, let us say 2 and 5, yielding the sum 7, we remark that the binary addition
of code for 2 and 5 generates the code word for 7.

2 = 0010 +
5 = 0101
7 = 0111

On the contrary, the BCD code 4221 is not an additive code, as:

2 = 0010 +
3 = 0011
0101
The combination 0101 does not correspond to the digit 5. Thus, 4221 BCD code is not an additive one.

6. The next criteria of classification are given by the number of bits used for encoding the decimal digits.
There may be distinguished two classes:

1. BCD codes with 4 bits;


2. BCD codes with more than 4 bits.

The codes with more than 4 bits are recommended especially for their protection properties. With these codes
we can detect and eventually correct errors of representation.

A new concept introduced here is the distance of the code. The distance is given by the number of differences
on two consecutive combinations in the sequence of code words used for encoding the digits.

Properties.
1. A code having the minimum distance 2 has the property of error detection.
2. If the minimum distance is 3 then the BCD is an error correction code.

Only codes with more than 4 bits may exhibit such properties. Among the BCD codes with 5 bits the
following three are very useful. They may be weighted, with keys, like Excess 11 or 3a+2, with self
complementing features and with parity protection like 74210 BCD code, etc.

DIGIT Excess 11 3a+2 74210


0 01011 00010 00000
1 01100 00101 00011
2 01101 01000 00101
3 01110 01011 00110
4 01111 01110 01001
5 10000 10001 01010
6 10001 10100 01100
7 10010 10111 10001
8 10011 11010 100010
9 10100 11101 10100

The BCD Excess 11 is a 5 bit BCD code, where the positions are designated b4b3b2b1b0 and a digit D is
represented as:

D = 16xb4 + 8xb3 + 4xb2 + 2xb1 + 1xb0 – 11


5
Let us take D=3; the corresponding word is 01110, as
3 = 16x0 + 8x1 + 4x1 + 2x1 + 1x0 – 11 = 8 + 4 + 2 – 11 = 3

This code presents self-complementing property, as the code words associated to pairs of 9’s complement
digits (0,9), (1,8), (2,7), (3,6), (4,5) are complemented.

The “3a+2” code is a 5 bit BCD code exhibiting the self-complementing property. “3a+2” formula gives the
decimal number to be coded according to the binary code, where “a” is a digit to be represented. For
instance, let us take a=3, then we have to represent the decimal number 3 x 3 + 2 = 11, that is 01011.
The BCD code 74210 is a weighted BCD code with exception for the 0 digit. It is useful for its protection
property as each code word contains exactly two 1 bits. If there are detected more or less than 2 1s, then an
error is signaled.

Definition:
A BCD is reflective if the 9’s complement combination of a word from the code is
formed simply by changing only one of its bits.

A reflective code is characterized by the fact that it is imaged about the centre with one bit changed.

Let us consider the following two BCD codes:

Decimal Code 1 Code 2


value ABCD ABCD
0 0 0 0 0 0 1 0 0
1 0 0 0 1 1 0 1 0
2 . 0 0 1 0 . 1 0 0 0
3 . 0 0 1 1 . 1 1 1 0
4 . 0 1 0 0 . 0 0 0 0
5 . 0 0 0 0 . 0 0 0 1
6 . 0 0 0 0 . 1 1 1 1
7 . 0 0 0 0 . 1 0 0 1
8 0 0 0 0 1 0 1 1
9 0 0 0 0 0 1 0 1

If we consider the decimal digit 2, then the binary associated combination is 0010 in Code 1 and 1000 in
Code 2. The 9’s complement of 2 is 7; the binary combination associated to 7 is 1010 in Code 1 and 1001 in
code 2.
If in case of Code 1 we compare the combinations 0010 and 1010 the conclusion is that they differ in only
the first position (one bit). Similarly, if we compare the combination 1000 and 1001 we conclude that they
differ only in one position. We can extend the analysis to all pairs as marked in the figure. The conclusion is
that both codes are belonging to the reflective codes class.

The definition can be expanded beyond the class of BCD codes. For example, let us consider a binary
codification for 16 digits (on 4 bits):

6
Decimal Four bits code
value ABCD
0 0 0 0 0
1 0 0 0 1
2 . 0 0 1 1
3 . 0 0 1 0
4 . 0 1 1 0
5 . 0 1 1 1
6 . 0 1 0 1
7 . 0 1 0 0
8 . 1 1 0 0
9 . 1 1 0 1
10 . 1 1 1 1
11 . 1 1 1 0
12 . 1 0 1 0
13 . 1 0 1 1
14 1 0 0 1
15 1 0 0 0

Any pair marked in the table satisfies the condition to differ in only one of its bits. On this code we can
define 15’s complement of a number.

Unit distance codes


There are applications in which it is desirable to represent numerical as well as other information with a code
that changes only one bit position from one code word to the next adjacent word. This class of codes is called
Unit Distance Code (UDC).

The unit distance property implies that only one bit changes in the next or adjacent code word independent of
the direction taken in the code sequence. The Unit Distance Codes have special advantages in that they
minimize transitional errors.

Definition:
Unit Distance Codes represent a special class of binary codes where two adjacent or
consecutive combinations differ in only one position.

A particular case of UDC is the Gray code. The Gray code is an interesting and useful code, that is both
reflective and unit distance. It can be derived directly from the natural binary code. In the next table there are
presented two Gray codes on 3 and 4 bits.

7
Decimal Three bits Gray code Four bits Gray code
value ABC ABCD
0 0 0 0 0 0 0 0
1 0 0 1 0 0 0 1
2 . 0 1 1 . 0 0 1 1
3 . 0 1 0 . 0 0 1 0
4 . 1 1 0 . 0 1 1 0
5 . 1 1 1 . 0 1 1 1
6 1 0 1 . 0 1 0 1
7 1 0 0 . 0 1 0 0
8 . 1 1 0 0
9 . 1 1 0 1
10 . 1 1 1 1
11 . 1 1 1 0
12 . 1 0 1 0
13 . 1 0 1 1
14 1 0 0 1
15 1 0 0 0

By a simple inspection we can see that these codes are Unit Distance Codes as the distance between any two
consecutive combinations is one. The top and the bottom rows are also considered adjacent.

Furthermore, the above presented code is reflective as it can be seen; the portion of the table below the
bisecting line is the reflection of the upper segment with the exception of the most significant bit. This
reflected binary code can be extended to five bits by continuing the table downwards, making the new fifth
msb 1 and reflecting all lesser bits. The process continues as required.

Decimal Five bits Gray code Five bits Gray code Decimal
value value
0 0 0 0 0 0 1 1 0 0 0 16
1 0 0 0 0 1 1 1 0 0 1 17
2 0 0 0 1 1 1 1 0 1 1 18
3 0 0 0 1 0 1 1 0 1 0 19
4 0 0 1 1 0 1 1 1 1 0 20
5 0 0 1 1 1 1 1 1 1 1 21
6 0 0 1 0 1 1 1 1 0 1 22
7 0 0 1 0 0 1 1 1 0 0 23
8 0 1 1 0 0 1 0 1 0 0 24
9 0 1 1 0 1 1 0 1 0 1 25
10 0 1 1 1 1 1 0 1 1 1 26
11 0 1 1 1 0 1 0 1 1 0 27
12 0 1 0 1 0 1 0 0 1 0 28
13 0 1 0 1 1 1 0 0 1 1 29
14 0 1 0 0 1 1 0 0 0 1 30
15 0 1 0 0 0 1 0 0 0 0 31

Potrebbero piacerti anche