**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:**

Decimal Number | BCD Code |

0 | 0000 |

1 | 0001 |

2 | 0010 |

3 | 0011 |

4 | 0100 |

5 | 0101 |

6 | 0110 |

7 | 0111 |

8 | 1000 |

9 | 1001 |

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:**

Decimal Number | BCD Code |

0 | 0000 |

1 | 0001 |

2 | 0010 |

3 | 0011 |

4 | 0100 |

5 | 0101 |

6 | 0110 |

7 | 0111 |

8 | 1000 |

9 | 1001 |

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:**

Decimal Number | 5211 Code |

0 | 0000 |

1 | 0001 |

2 | 0011 |

3 | 0101 |

4 | 0111 |

5 | 1000 |

6 | 1010 |

7 | 1100 |

8 | 1110 |

9 | 1111 |

**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:**

Decimal Digit | BCD Code | Excess-3 Code |

0 | 0000 | 0011 |

1 | 0001 | 0100 |

2 | 0010 | 0101 |

3 | 0011 | 0110 |

4 | 0100 | 0111 |

5 | 0101 | 1000 |

6 | 0110 | 1001 |

7 | 0111 | 1010 |

8 | 1000 | 1011 |

9 | 1001 | 1100 |

_{10}is;

**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.

Decimal Numbers | Gray Code |

0 | 0000 |

1 | 0001 |

2 | 0011 |

3 | 0010 |

4 | 0110 |

5 | 0111 |

6 | 0101 |

7 | 0100 |

8 | 1100 |

9 | 1101 |

10 | 1111 |

11 | 1110 |

12 | 1010 |

13 | 1011 |

14 | 1001 |

15 | 1000 |

**Advantages of Binary Codes**

- Binary codes are simple, and they consist of only two digits, 0 and 1. The codes can be easily implemented in electronic circuits with faster processing.
- The digital electronics circuit functions with on/off states, and binary is the natural language of computers. Therefore, the binary system( 0 and 1 states) is a perfect fit for representing these states.
- The redundancy in the binary codes can be done to detect errors in data storage and communication.
- Electronic systems and computers do binary operations, such as AND, OR, and NOT, which form the basis of digital logic. These codes are very simple to perform all these logic operations.
- Digital data can be stored more efficiently in binary format. These codes need less space on storage devices—the codes best fit where space is a critical factor.
- Binary arithmetic operation is much simpler than decimal arithmetic because the binary operation has only two digits, 0 and 1. The use of binary codes simplifies the design of arithmetic logic units (ALUs) in processors.
- Binary is a universal language in digital electronics, and therefore, the different devices operating on this system can be easily interfaced.
- These codes are useful for a machine language, the lowest-level programming language understood by computers and digital electronics.

**Conclusion**

In conclusion, binary codes play a vital role in digital electronics. They represent information in binary forms that digital systems like computers can understand and process. In this article, we have explained all the commonly used types of binary codes in detail with the help of examples.