# Types of Binary Codes- 8421,2421,5211, Excess-3, Gray

Binary codes are basically ways of representing information using binary digits, i.e., 0s and 1s. In digital electronics, various binary codes, such as BCD, 2421,5211, Ex-3, Gray, and ASCII, are used to represent text and numeric data.

## Types of Binary Codes

The codes can be majorly classified into the following two categories:

• Weighted Codes
• BCD Code or 8421 Code
• 2421 Code
• 5211 Code
• Non-weighted Codes
• Excess-3 Code
• Gray Code

Let us now discuss these codes in detail.

### (1). Weighted Codes

The type of binary code in which the value of the digit depends on its position in the number is called weighted code. Hence, in weighted codes, each position in a binary number has a specific weight associated with it.

For example, consider a given binary number (1001), then

Hence, in this binary number, the positional weight of the ‘1’ at the LSB position is ‘1’, whereas the positional value of the 1 at the MSB position is ‘8’.

Now, let us discuss some examples of weight codes.

#### (a). BCD Code or 8421 Code:

BCD (Binary Coded Decimal) code is a binary code used to represent the decimal numbers, i.e., 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9 in Binary form. The decimal numbers and their BCD codes are represented in the following table. In the case of BCD codes, each decimal digit is expressed as a group of 4 bits.

Since it is a weighted code, the 4 Bits can be expressed in terms of their place value from left to right as 8421, i.e.,

BCD Code Table:

The 8421 BCD code is also known as sequential code because two adjacent binary codes differ by one digit.

### (b). 2421 Code:

Similar to the BCD or 8421 code, the 2421 code is another type of weighted code used in digital systems. This code measures the positional weights as 2 4 2 1.

The following table gives the decimal numbers and their corresponding 2421 codes.

2421 Code Table:

The 8421 BCD code is also known as sequential code because two adjacent binary codes differ by one digit only in this type of binary code.

#### (c). 5211 Code:

The 5211 code is another 4-bit weighted binary code in which the positional weight is expressed as 5, 2, 1, and 1 from left to right.

The following table shows the decimal digits and their corresponding 5211 codes.

5211 Code Table:

Note – From the tables of the 2421 code and 5211 code, it is clear that the binary code for decimal 9 is the complement of the binary code for decimal 0; similarly, the binary code or decimal 8 is the complement of the binary code for decimal 1, and so on. Such codes are referred to as Reflective Codes.

### (2). Non-Weighted Codes

In some binary codes, there is no relation between the value of the digit and its position in the number; such codes are termed non-weighted binary codes. The non-weighted codes are used in special applications where the positional weight is not crucial. Common examples of non-weighted binary codes include Excess-3 codes and gray codes.

Now, let us discuss the Excess-3 codes and gray codes in detail.

#### (a). Excess-3 Codes:

Excess-3 code, also called XS-3 code or Ex-3 code, is a type of non-weighted binary code. The Ex-3 code is a 4-bit code that is obtained by adding 3 to a BCD 8421 code.

For example, the Ex-3 code for 3 (0011) in the BCD code is equal to 3 (0110) in the Excess-3 code.

Now, the number 6 is converted into BCD(8421 code)

Therefore, the excess-3 code of decimal number 3 is 0110.

The decimal numbers and their corresponding Ex-3 codes are listed in the following table.

Excess-3 Code Table:

Excess-3 code of (175.27)10 is (010010101000.00111010).

#### (b). Gray Code:

The gray code is another non-weighted binary code in which one bit differs from the preceding number. It is a type of reflective binary code, as in this code, the two successive codes differ by only one binary digit.

For example, the decimal numbers 8 and 9 are represented in gray code as 1100 and 1101, respectively. These two codes differ only in a single position or a single bit, that is, the first position from the right. For this reason, the gray code is also called Unit Distance Code. Similar to Ex-3 codes, the gray codes are also used in special applications in digital electronics.

The table representing decimal digits and their corresponding gray codes is given below.