# Code Converters

Numbers are usually coded in one form or another so as to represent or use it as required. For instance, a number ‘nine’ is coded in decimal using symbol (9)d. Same is coded in natural-binary as (1001)b. While digital computers all deal with binary numbers, there are situations wherein natural-binary representation of numbers in in-convenient or in-efficient and some other (binary) code must be used to process the numbers.

One of these other code is gray-code, in which any two numbers in sequence differ only by one bit change. This code is used in K-map reduction technique. The advantage is that when numbers are changing frequently, the logic gates are turning ON and OFF frequently and so are the transistors switching which characterizes power consumption of the circuit; since only one bit is changing from number to number, switching is reduced and hence is the power consumption.

Let’s discuss the conversion of various codes from one form to other.

## Binary-to-Gray

The table that follows shows natural-binary numbers (upto 4-bit) and corresponding gray codes.

Looking at gray-code (G3G2G1G0), we find that any two subsequent numbers differ in only one bit-change.

The same table is used as truth-table for designing a logic circuitry that converts a given 4-bit natural binary number into gray number. For this circuit, B3 B2 B1 B0 are inputs while G3 G2 G1 G0 are outputs.

K-map for the outputs:

**And** ** G3 = B3**

## Gray-to-Binary

The table that follows shows natural-binary numbers (upto 4-bit) and corresponding gray codes.

Looking at gray-code (G3G2G1G0), we find that any two subsequent numbers differ in only one bit-change.

The same table is used as truth-table for designing a logic circuitry that converts a given 4-bit natural binary number into gray number. For this circuit, B3 B2 B1 B0 are inputs while G3 G2 G1 G0 are outputs.

K-map for the outputs:

**And** **B3 = G3**

The realization of Gray-to-Binary converter is