- Digital Electronics Tutorial
- Digital Electronics - Home
- Digital Electronics Basics
- Types of Digital Systems
- Types of Signals
- Logic Levels And Pulse Waveforms
- Digital System Components
- Digital Logic Operations
- Digital Systems Advantages
- Number Systems
- Number Systems
- Base Conversions
- Binary Numbers Representation
- Binary Arithmetic
- Signed Binary Arithmetic
- Octal Arithmetic
- Hexadecimal Arithmetic
- Complement Arithmetic
- Binary Codes
- Binary Codes
- 8421 BCD Code
- Excess-3 Code
- Gray Code
- ASCII Codes
- EBCDIC Code
- Code Conversion
- Error Detection & Correction Codes
- Logic Gates
- Logic Gates
- AND Gate
- OR Gate
- NOT Gate
- Universal Gates
- XOR Gate
- XNOR Gate
- CMOS Logic Gate
- Two Level Logic Realization
- Threshold Logic
- Boolean Algebra
- Boolean Algebra
- Laws of Boolean Algebra
- Boolean Functions
- DeMorgan's Theorem
- SOP and POS Form
- Minimization Techniques
- K-Map Minimization
- Three Variable K-Map
- Four Variable K-Map
- Five Variable K-Map
- Six Variable K-Map
- Don't Care Condition
- Quine-McCluskey Method
- Min Terms and Max Terms
- Canonical and Standard Form
- Max Term Representation
- Simplification using Boolean Algebra
- Combinational Logic Circuits
- Digital Combinational Circuits
- Digital Arithmetic Circuits
- Multiplexers
- Parity Bit Generator and Checker
- Comparators
- Encoders
- Keyboard Encoders
- Priority Encoders
- Decoders
- Demultiplexers
- Arithmetic Logic Unit
- 7-Segment LED Display
- Code Converters
- Code Converters
- Binary to Decimal Converter
- Decimal to BCD Converter
- BCD to Decimal Converter
- Binary to Gray Code Converter
- Gray Code to Binary Converter
- BCD to Excess-3 Converter
- Excess-3 to BCD Converter
- Adders
- Half Adders
- Full Adders
- Serial Adders
- Parallel Adders
- Full Adder using Half Adder
- Half Adder vs Full Adder
- Binary Adder-Subtractor
- Subtractors
- Half Subtractors
- Full Subtractors
- Parallel Subtractors
- Full Subtractor using 2 Half Subtractors
- Half Subtractor using NAND Gates
- Sequential Logic Circuits
- Digital Sequential Circuits
- Clock Signal and Triggering
- Latches
- Flip-Flops
- Conversion of Flip-Flops
- Shift Registers
- Shift Register Applications
- Counters
- Finite State Machines
- Algorithmic State Machines
- A/D and D/A Converters
- Analog-to-Digital Converter
- Digital-to-Analog Converter
- DAC and ADC ICs
- Realization of Logic Gates
- NOT Gate from NAND Gate
- OR Gate from NAND Gate
- AND Gate from NAND Gate
- NOR Gate from NAND Gate
- XOR Gate from NAND Gate
- XNOR Gate from NAND Gate
- NOT Gate from NOR Gate
- OR Gate from NOR Gate
- AND Gate from NOR Gate
- NAND Gate from NOR Gate
- XOR Gate from NOR Gate
- XNOR Gate from NOR Gate
- NAND/NOR Gate using CMOS
- Memory Devices
- Memory Devices
- RAM and ROM
- Cache Memory Design
- Programmable Logic Devices
- Programmable Logic Devices
- Programmable Logic Array
- Programmable Array Logic
- Field Programmable Gate Arrays
- Digital Electronics Families
- Digital Electronics Families
- CPU Architecture
- CPU Architecture
Digital Electronics - Code Conversion
In digital electronics, we use different types of binary codes depending on the specifications of the digital systems. For proper data exchange among different digital systems, an essential process is carried out called code conversion.
Code conversion is the process of converting a digital code from one format to another. Code conversion is considered an essential process in various digital systems like computers, microcontrollers, communication systems, etc.
In this chapter, we will study the following major code conversions −
- Binary to BCD Code Conversion
- BCD to Binary Code Conversion
- Binary to Gray Code Conversion
- Gray to Binary Code Conversion
- BCD to Excess-3 Code Conversion
- Excess-3 to BCD Code Conversion
- Exces-3 to Gray Code Conversion
- Gray to Excess-3 Code Conversion
Let us understand each type of code conversion in detail with the help of examples.
Binary to BCD Code Conversion
BCD stands for Binary Coded Decimal. Hence, BCD is a decimal number represented in binary format. The conversion of pure binary into BCD is done as per the following steps −
Step 1 − Convert the given pure binary number into its equivalent decimal number.
Step 2 − Convert the obtained decimal number into BCD code.
Let us understand the binary to BCD code conversion through an example.
Example
Convert (100111)2 into BCD code.
Solution
The given binary is,
Binary = 100111
The decimal equivalent of given binary is
1 × 25 + 0 × 24 + 0 × 23 + 1 × 22 + 1 × 21 + 1 × 20
= 1 × 32 + 0 × 16 + 0 × 8 + 1 × 4 + 1 × 2 + 1 × 1
= 32 + 0 + 0 + 4 + 2 + 1 = (39)10
Now, converting (39)10 into BCD code, we get,
(3)10 = (0011)BCD
(9)10 = (1001)BCD
Thus, the BCD equivalent of the given binary number is,
(100111)2 = (0011 1001)BCD
BCD to Binary Code Conversion
BCD to binary code conversion is the reverse process of binary to BCD code conversion as discussed previously.
The BCD to binary code conversion is performed as per the following steps −
Step 1 − Convert the given BCD code into its equivalent decimal format.
Step 2 − Convert the obtained decimal to the equivalent binary format.
The following example demonstrates the BCD to binary code conversion.
Example
Convert (1001 0111 0010)BCD into binary code.
Solution
Converting the given BCD code into decimal equivalent −
(1001)BCD = (9)10
(0111)BCD = (7)10
(0010)BCD = (2)10
Thus, the decimal equivalent of the given BCD is
(1001 0111 0010)BCD = (972)10
Now, converting the obtained decimal to equivalent binary,
Thus, the binary equivalent of (1001 0111 0010)BCD is (1111001100)2.
Binary to Gray Code Conversion
The process of converting a binary number into its equivalent gray code is termed as binary to gray code conversion. We know that the gray code is a binary coding scheme where two successive codes are differed in one bit only.
The step-by-step procedure to convert a binary code into gray code is explained below −
Consider the given binary code is Bn Bn-1 Bn-2 … B2 B1 and the equivalent gray code is Gn Gn-1 Gn-2 … G2 G1. Then,
Step 1 − Write the most significant bit (MSB) or left most bit (Bn) of the binary code as the left most bit of the gray code (Gn), i.e.,
Gn = Bn
Step 2 − XOR the MSB (Bn) and the next bit(Bn-1) of the binary code. Record the result as the next bit of the gray code (Gn-1) i.e.,
$$\mathrm{G_{n-1} \: = \: B_{n} \oplus B_{n-1}}$$
Step 3 − XOR the next bits Bn-1 and Bn-2, record the result as the next bit of the gray code (Gn-2), i.e.,
$$\mathrm{G_{n-2} \: = \: B_{n-1} \oplus B_{n-2}}$$
Step 4 − Repeat this process until all the bits of the given binary code are exhausted. The obtained code will be the equivalent gray code.
Let us understand the conversion of binary to gray code with the help of an example.
Example
Convert (110110)2 into its equivalent gray code.
Solution
The given binary code is,
Binary = 110110
Converting the given binary into its equivalent gray code,
Hence, the equivalent gray code (101101)gray
Gray to Binary Code Conversion
The process of translating a gray code into its equivalent binary code is called gray to binary code conversion. The conversion of a given gray code into the equivalent binary code is done as per the following steps −
Consider the given gray code is Gn Gn-1 Gn-2 … G2 G1 and the binary code is Bn Bn-1 Bn-2 … B2 B1. Then,
Step 1 − The left most bit or MSB of the equivalent binary code is same as the MSB of the gray code, thus, copy it, i.e.,
Bn = Gn
Step 2 − XOR the MSB of the binary number Bn and the next significant bit of the gray code (Gn-1). Record it as the next significant bit of the binary number, i.e.,
$$\mathrm{B_{n-1} \: = \: B_{n} \oplus G_{n-1}}$$
Step 3 − XOR the bit Bn-1 and the next significant bit of the gray code (Gn-2). Record the result as the next significant bit of the binary number, i.e.,
$$\mathrm{B_{n-2} \: = \: B_{n-1} \oplus G_{n-2}}$$
Step 4 − Continue this process until all the gray code bits are exhausted. The obtained sequence of bits will be the pure binary code equivalent of the given gray code.
Let us take an example to understand the conversion of gray code to equivalent binary code.
Example
Convert the gray code (110010)gray into its equivalent binary code.
Solution
The conversion of gray code into binary is done as given below −
Hence, the binary equivalent of (110010)gray is (100011)2.
BCD to Excess-3 Code Conversion
The process of translating a given BCD (binary coded decimal) into its equivalent excess-3 code is referred to as BCD to excess-3 code conversion.
To convert a BCD code into its equivalent excess-3 code, we follow the steps given below −
Step 1 − Add 0011 (3) to each 4-bit group of given BCD code.
Step 2 − The resulting code will be the equivalent XS-3 code.
It is important to note that in XS-3 code, there are six invalid bit combinations. They are 0000, 0001, 0010, 1101, 1110, and 1111.
Let us take an example to understand the BCD to excess-3 code conversion.
Example
Convert (0011 1001 1000)BCD into its equivalent XS-3 code.
Solution
The conversion of given BCD code into its equivalent XS-3 code is shown below −
BCD Code | 0011 | 1001 | 1000 |
Adding 0011 | 0011 | 0011 | 0011 |
XS-3 Code | 0110 | 1100 | 1011 |
Thus, the equivalent XS-3 code of (0011 1001 1000)BCD is (0110 1100 1011)XS-3.
Excess-3 to BCD Code Conversion
The process of converting a given XS-3 code into its equivalent BCD (binary coded decimal) code is known as excess-3 to BCD code conversion.
The conversion of excess-3 code into BCD code is done as per the following steps −
Step 1 − Subtract 0011 (3) from the each 4-bit group of XS-3 code.
Step 2 − The resulting code will be the BCD code equivalent of the given XS-3 code.
Let us understand the excess-3 to BCD code conversion with the help of an example.
Example
Convert (1100 1001 0110)XS-3 into its equivalent BCD code.
Solution
The conversion of XS-3 code to BCD code is given below −
XS-3 Code | 1100 | 1001 | 0110 |
Subtracting 0011 | 0011 | 0011 | 0011 |
BCD Code | 1001 | 0110 | 0011 |
Hence, the equivalent BCD code of (1100 1001 0110)XS-3 is (1001 0110 0011)BCD.
Conclusion
In conclusion, code conversion is the process of converting a binary code from one format to another. For example, we can convert a BCD code into its equivalent pure binary code, or an XS-3 code into its equivalent BCD code, etc. In this chapter, we explained different types of code conversion.