Last Updated on October 25, 2023 by Electricalvolt

In this article, we will study the concept of code conversion in digital electronics. As we know, several types of codes are used in digital electronics to represent and process digital information. The same information can be represented in different codes depending on the system type and application requirements. However, while processing, transmitting, or exchanging information among different digital systems, its conversion is to be performed so that the designated system can read and interpret the information correctly.

This article describes the basic meaning of code conversion and some majorly used code conversions in digital electronics.

**What is a Code?**

In digital electronics, the information is represented as letters, digits, and symbols. A group of these letters, digits, and symbols representing a piece of certain information is called a code. For example, in BCD (Binary Coded Decimal), 8 is represented as 1000. Hence, in BCD, the 1000 is a code for 8 in decimal.

There are several types of codes widely used in digital electronics. Some examples of these codes are binary codes, BCD codes, Excess-3 codes, gray codes, etc.

**What is Code Conversion?**

Converting a code from one form to another is called code conversion. Hence, code conversion is a method that helps us to transform the information from one code format to another. Code conversion is an essential process in computing and digital electronics.

**Key Code Conversion Techniques**

The following four code conversion techniques are most widely used in digital systems and computers:

- Binary to BCD Code Conversion
- BCD to Binary Code Conversion
- BCD to XS-3 Code Conversion
- XS-3 to BCD Code Conversion

Before discussing the code conversion from one code format to another, let us know about these codes.

**What is a Binary Code?**

A binary code is a conventional coding system that expresses information in digital format. It is the most widely used code format in digital computers. In this code format, the digital information is expressed as a string of 1s and 0s in a binary number system.

**What is the BCD Code?**

BCD stands for Binary Coded Decimal. It is a code format used to represent decimals as binary digits. It is a 4-bit code. It is also known as 8421-code. BCD code has a unique 4-bit binary code for each decimal digit from 0 to 9.

**What is the XS-3 Code?**

The XS-3 code or Excess-3 code, is a binary code obtained by adding 3 (0011) to the ordinary BCD code. It is a non-weighted code format for representing decimals.

Let us learn how to convert a code from one format to another.

**(1). Binary Code to BCD Code Conversion**

In this section, we will learn how to convert an ordinary binary code into a BCD or Binary coded decimal.

To convert a binary code into BCD code, we first convert the given binary code into decimal code, then convert decimal code to BCD. Let us understand this process with the help of an example.

**Example – Convert (1101101)**_{2} into BCD.

_{2}into BCD.

**Solution –** The given binary number is (1101101)_{2}.

**Step 1: Convert the binary number to decimal.**

The decimal equivalent for this binary number is,

Weight | 2^{6} | 2^{5} | 2^{4} | 2^{3} | 2^{2} | 2^{1} | 2^{0} |

Bit | 1 | 1 | 0 | 1 | 1 | 0 | 1 |

Value | 1 × 2^{6} | 1 × 2^{5} | 0 × 2^{4} | 1 × 2^{3} | 1 × 2^{2} | 0 × 2^{1} | 1 × 2^{0} |

64 | 32 | 0 | 8 | 4 | 0 | 1 |

Therefore, the decimal number for the given binary code is,

**(1101101) _{2} = 64 + 32 + 0 + 8 + 4 + 0 + 1 = (109)_{10}**

**Step 2: Convert decimal number to BCD**

Now, let us convert this decimal number to equivalent BCD code as,

BCD Weights | 8 | 4 | 2 | 1 |

BCD of 1 | 0 | 0 | 0 | 1 |

BCD of 0 | 0 | 0 | 0 | 0 |

BCD of 9 | 1 | 0 | 0 | 1 |

Hence, the 109 in decimal in BCD is expressed as follows:

**(1101101) _{2} = (109)_{10} = (0001 0000 1001)_{BCD}**

Hence, this is how we can convert a given binary number into BCD code.

**Binary to BCD Code Conversion Table:**

The following table can be used to convert an ordinary binary number into BCD code:

Binary | Decimal | BCD |

0 | 0 | 0000 |

1 | 1 | 0001 |

10 | 2 | 0010 |

11 | 3 | 0011 |

100 | 4 | 0100 |

101 | 5 | 0101 |

110 | 6 | 0110 |

111 | 7 | 0111 |

1000 | 8 | 1000 |

1001 | 9 | 1001 |

**Table 1: Binary to BCD Code Conversion Table**

**(2). BCD Code to Binary Code Conversion**

We can convert a given BCD code into its equivalent binary code. This process involves the conversion of a given BCD code into the decimal and then to the binary code.

Let us take an example to understand how to convert a BCD code into binary code.

**Example – Convert (0001 1001 0001)**_{BCD} into binary code.

_{BCD}into binary code.

**Solution **– The given BCD code is (0001 1001 0001)_{BCD}.

**Step 1: Convert the BCD number to decimal**

The equivalent decimal for the given BCD code is,

**(0001 1001 0001) _{BCD} = 191 (referring to the above-given table 1)**

**Step 2: Convert decimal to binary**

Now, convert this decimal into binary code as follows.

Decimal | Division | Remainder |

191 | 191/2 = 95 | 1 |

95 | 95/2 = 47 | 1 |

47 | 47/2 = 23 | 1 |

23 | 23/2 = 11 | 1 |

11 | 11/2 = 5 | 1 |

5 | 5/2 = 2 | 1 |

2 | 2/2 = 1 | 0 |

Hence, the equivalent binary code is

**(0001 1001 0001) _{BCD} = (191)_{10} = (0111111)_{2}**

Hence, this is how we can convert a given BCD code into binary code.

**(3). BCD Code to XS-3 Code Conversion**

To convert a BCD code into XS-3 code, we first have to convert the given BCD into decimal, then add 3 to the obtained decimal number, and finally, we convert this decimal into binary to obtain the equivalent XS-3 code.

Let us take an example to understand this process of converting a BCD code into an XS-3 code.

**Example – Convert (1001 0111)**_{BCD} into XS-3 code.

_{BCD}into XS-3 code.

**Solution** – The given BCD code is,

**Step 1 − Convert to decimal**

**(1001 0111) _{BCD}= (97)_{10}**

**Step 2 − Add 3 to decimal**

Now, we add (3)_{10} to each digit of 97, i.e.

(9)_{10} + (3)_{10} = (12)_{10}

(7)_{10} + (3)_{10} = (10)_{10}

**Step 3 − Convert to Excess-3**

Let us convert (97)_{10} into binary to obtain the equivalent excess-3 code.

Decimal | 9 | 7 |

Decimal + 3 | 12 | 10 |

XS-3 Code | 1100 | 1010 |

Combining all these binary terms to obtain the final XS-3 code.

**(1001 0111) _{BCD}= (97)_{10} = (1100 1010)_{XS-3}**

This is how we can convert a BCD code into an XS-3 code.

**(4). XS-3 Code to BCD Code Conversion**

This is the reverse process of the previous conversion. We convert a given excess-3 code into the equivalent BCD code.

Let us take an example to understand how this conversion takes place.

**Example –Convert (1001 1010)**_{XS-3} into BCD code.

_{XS-3}into BCD code.

**Solution** – The given XS-3 code is (1001 1010)_{XS-3}.

**Step 1 − Convert Excess-3 code to decimal**

Firstly, convert this XS-3 code into decimal as,

(1001 1010)_{XS-3}= (9)_{10} (10)_{10}

**Step 2 − Subtract-3 code from decimal code(step1)**

Subtracting -3 from each digit to obtain the actual decimal.

(9)_{10} – (3)_{10} = (6)_{10}

(10)_{10} – (3)_{10} = (7)_{10}

Hence, the decimal equivalent to the given XS-3 is 67.

**Step 3 − Convert decimal number(step 2) into BCD**

Let us convert this decimal 67 into binary to obtain the equivalent BCD code.

(6)_{10} = (0110)_{BCD}

(7)_{10} = (0111)_{BCD}

Hence, the equivalent BCD code is,

**(1001 1010) _{XS-3}= (0110 0111)_{BCD}**

Hence, in this article, we have explained the conversion of codes in digital electronics.