Code Conversion – Definition and Process

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.

Solution – The given binary number is (1101101)2.

Step 1: Convert the binary number to decimal.

The decimal equivalent for this binary number is,

Weight26252423222120
Bit1101101
Value1 × 261 × 250 × 241 × 231 × 220 × 211 × 20
 643208401

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 Weights8421
BCD of 10001
BCD of 00000
BCD of 91001

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:

BinaryDecimalBCD
000000
110001
1020010
1130011
10040100
10150101
11060110
11170111
100081000
100191001
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.

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.

DecimalDivisionRemainder
191191/2 = 951
9595/2 = 471
4747/2 = 231
2323/2 = 111
1111/2 = 51
55/2 = 21
22/2 = 10

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.

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.

Decimal97
Decimal + 31210
XS-3 Code11001010

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.

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.

Leave a Comment