You are on page 1of 12

CODE CONVERTERS

AIM :
To design and implement a digital combinational circuit that converts the given code
in

Binary to Gray code and vice versa


Excess 3 code to BCD code and vice versa

Components Required :
1.
2.
3.
4.
5.
6.

Digital IC Trainer kit


IC 7404
IC 7408
IC 7432
IC 7486
Connecting Wires

1
-

1
1
1
1
Required quantity

Theory :
While the binary system of representation is the most extensively used one in digital
systems, including computers, octal and hexadecimal number systems are commonly used for
representing groups of binary digits. The binary coding system, called the straight binary
code becomes very cumbersome to handle when used to represent larger decimal numbers. To
overcome this shortcoming, and also to perform many other special functions, several binary
codes have evolved over the years. Some of the better-known binary codes, including those
used efficiently to represent numeric and alphanumeric data, and the codes used to perform
special functions, such as detection and correction of errors. Coding was defined as the use of
groups of bits to represent items of information that are multivalued. Assigning each item of
information a unique combination of bits makes a transformation of the original information.
This we recognize as information being processed into another form. Moreover, we have seen
that there are many coding schemes exist. Different digital systems may use different coding
schemes. It is sometimes necessary to use the output of one system as the input to other.
Therefor a sort of code conversion is necessary between the two systems to make them
compatible for the same information. A code converter is a combinational logic circuit that
changes data presented in one type of binary code to another type of binary code. A general
block diagram of a code converter is shown in Fig.

Fig. Code converter

Gray Code
The Gray code was designed by Frank Gray at Bell Labs and patented in 1953. It is an
unweighted binary code in which two successive values differ only by 1 bit. Owing to this
feature, the maximum error that can creep into a system using the binary Gray code to encode
data is much less than the worst-case error encountered in the case of straight binary
encoding. An examination of the four-bit Gray code numbers shows that the last entry rolls
over to the first entry. That is, the last and the first entry also differ by only 1 bit. This is
known as the cyclic property of the Gray code.

BinaryGray Code Conversion


A given binary number can be converted into its Gray code equivalent by going through the
following steps:
1. Begin with the most significant bit (MSB) of the binary number. The MSB of the Gray
code equivalent is the same as the MSB of the given binary number.
2. The second most significant bit, adjacent to the MSB, in the Gray code number is obtained
by adding the MSB and the second MSB of the binary number and ignoring the carry, if any.
That is, if the MSB and the bit adjacent to it are both 1, then the corresponding Gray code
bit would be a 0.
3. The third most significant bit, adjacent to the second MSB, in the Gray code number is
obtained by adding the second MSB and the third MSB in the binary number and ignoring the
carry, if any.
4. The process continues until we obtain the LSB of the Gray code number by the addition of
the LSB and the next higher adjacent bit of the binary number.
Gray CodeBinary Conversion
A given Gray code number can be converted into its binary equivalent by going through the
following steps:
1. Begin with the most significant bit (MSB). The MSB of the binary number is the same as
the MSB of the Gray code number.
2. The bit next to the MSB (the second MSB) in the binary number is obtained by adding the
MSB in the binary number to the second MSB in the Gray code number and disregarding the
carry, if any.
3. The third MSB in the binary number is obtained by adding the second MSB in the binary
number to the third MSB in the Gray code number. Again, carry, if any, is to be ignored.
4. The process continues until we obtain the LSB of the binary number.
Applications
1. The Gray code is used in the transmission of digital signals as it minimizes the occurrence
of errors.
2. The Gray code is preferred over the straight binary code in angle-measuring devices. Use
of the Gray code almost eliminates the possibility of an angle misread, which is likely if the
angle is represented in straight binary. The cyclic property of the Gray code is a plus in this
application.
3. The Gray code is used for labelling the axes of Karnaugh maps, a graphical technique used
for minimization of Boolean expressions.
4. The use of Gray codes to address program memory in computers minimizes power
consumption. This is due to fewer address lines changing state with advances in the program
counter.
5. Gray codes are also very useful in genetic algorithms since mutations in the code allow for
mostly incremental changes. However, occasionally a one-bit change can result in a big leap,
thus leading to new properties.
Excess-3 Code
The excess-3 code is another important BCD code. It is particularly significant for
arithmetic operations as it overcomes the shortcomings encountered while using the 8421
BCD code to add two decimal digits whose sum exceeds 9. The excess-3 code has no such
limitation, and it considerably simplifies arithmetic operations. Table 2.2 lists the excess-3
code for the decimal numbers 09. The excess-3 code for a given decimal number is

determined by adding 3 to each decimal digit in the given number and then replacing each
digit of the newly found decimal number by its four-bit binary equivalent. It may be
mentioned here that, if the addition of 3 to a digit produces a carry, as is the case with the
digits 7, 8 and 9, that carry should not be taken forward. The result of addition should be
taken as a single entity and subsequently replaced with its excess-3 code equivalent. Another
significant feature that makes this code attractive for performing arithmetic operations is that
the complement of the excess-3 code of a given decimal number yields the excess-3 code for
9s complement of the decimal number. As adding 9s complement of a decimal number B to
a decimal number A achieves A B, the excess-3 code can be used effectively for both
addition and subtraction of decimal numbers.
4-bit Binary to Gray code conversion
1. The block diagram of a 4-bit binary to gray code converter is shown in Fig.

If has four inputs (B3B2B1B0) representing 4-bit binary numbers and four outputs (G3G2G1G0)
representing 4-bit gray code.
Truth table for binary to gray code converters

solving all the gray outputs distantly with respect to binary inputs From the truth table; the
logic expressions for the gray code outputs can be written as
G3 = (8, 9, 10, 11, 12, 13, 14, 15)

G2 = (4, 5, 6, 7, 8, 9, 10, 11)


G1 = (2, 3, 4, 5, 10, 11, 12, 13)
G0 = (1, 2, 5, 6, 9, 10, 13, 14).

The above expressions can be simplified using K-map


Map for G3:

From the octet, we get


G3 = B 3
Map for G2:

From the two quads, we get


G2 = B3' B2 + B3 B2'
= B3 B2.
Map for G1:

From the two quads, we get


G1 = B2 B1' + B2' B1
= B2 B1
Map for G0:

From the two quads, we get


G0 = B1'B0 + B1B0'
= B1 B0.
G3 =
G2 =
G1 =
G0 =

B3
B3 B2
B2 B1
B1 B0.

Now the above expressions can be implemented using X-OR gates to yield the desired code
converter circuit shown in Fig.

4-bit Gray code to Binary code conversion


The block diagram of a 4-bit Gray code to binary code converter is shown in Fig. below

If has four inputs (G3G2G1G0) representing 4-bit Gray code and four outputs (B3B2 B1B0)
representing 4-bit Binary number.
TRUTH TABLE:
GRAY INPUT
G3
G2
G1
0
0
0
0
0
0
0
0
1
0
0
1
0
1
0
0
1
0
0
1
1
0
1
1
1
0
0
1
0
0
1
0
1
1
0
1
1
1
0
1
1
0
1
1
1
1
1
1

G0
0
1
0
1
0
1
0
1
0
1
0
1
0
1
0
1

B3
0
0
0
0
0
0
0
0
1
1
1
1
1
1
1
1

BINARY OUTPUT
B2
B1
0
0
0
0
0
1
0
1
1
1
1
1
1
0
1
0
1
1
1
1
1
0
1
0
0
0
0
0
0
1
0
1

B0
0
1
1
0
1
0
0
1
1
0
0
1
0
1
1
0

Now we solve all the Binary outputs. From the truth table, the logic expressions for the
Binary coded outputs can be written as :
B3 =
B2 =
B1 =
B0 =

( m8, m9, m10, m11, m12, m13, m14, m15)


( m4, m5, m6 m7, m8, m9, m10, m11)
(m2, m3, m4, m5, m8, m9, m14, m15)
(m1, m2, m4, m7, m8, m11, m13, m14).

These expressions can be simplified using k-map

Map for B3

B3 = G3

Map for B2

Map for B1

Map for B0

B3 =
B2 =
B1 =
B0 =

G3
G3 G2
G3 G2G1
G3 G2 G1 G0.

Now the above expressions can be implemented using X-OR gates to yield the desired code
converter circuit shown in Fig.

XS-3 to BCD code converter


The block diagram of an XS-3 to BCD code converter is shown in Fig. It has four
inputs (E3,E2,E1,E0) representing 4 bit XS-3 number and four outputs (B 3B2B1B0) representing
4-bit BCD code.

XS-3 codes are obtained from BCD code by adding 3 to each coded number. Moreover 4
binary variables may have 16 combinations, but only 10 are listed. The six not listed are dont
care-combinations. Since they will never occur, we are at liberty to assign to the output

variable either a 1 or a 0, whichever gives a simpler circuit. In this particular example, the
unused i/o combinations are listed below the truth table.
Truth Table for XS-3 to BCD code converter

Now we solve all the BCD outputs. From the truth table, the logic expressions for the BCD
coded outputs can be written as :
B3 =
B2 =
B1 =
B0 =

(m11, m12), d (m0, m1, m2, m13, m14, m15)


(m7, m8, m9, m10), d (m0, m1, m2, m13, m14, m15)
(m5, m6, m9, m10), d (m0, m1, m2, m13, m14, m15)
(m4, m6, m8, m10, m12), d (m0, m1, m2, m13, m14, m15).

These expressions can be simplified using k-map


Map for B3

B3 = E3 E2 + E3E1E0
Map for B2

B2 = E2' E0' + E2 E1 E0 + E2E1

Map for B1

B1 = E1' E0 + E1 E0'
= E1 E0
Map for B0

B0 = E0'
B3 =
B2 =
B1 =
B0 =

E3 E2 + E3 E1 E0
E2' E0' + E2 E1 E0 + E2'E1'
E1 E0
E0'

The expressions for BCD outputs (B3 B2 B1 B0) can be implemented for terms of inputs
(E3 E2 E1 E0) to form a XS-3 to BCD code converter circuit as below

E3
E2

E1
E0

6
5

E1 E0

4
2

3
2

B2 = E2' E0' + E2 E1 E0 +
E2'E1'
3

B1

B0 = E50'

B3 = E3 E2 + E3

2
2

E0
6

E1

BCD to Excess-3 Code converter:


The input is a BCD code word. Since this is a 4-bit code that represents a decimal
digit (0-to-9), there will be 4 input bits which will be represented by four input variables
B3,B2,B1, and B0. Output is a 4-bit excess-3 code (E 3, E2, E1 ,E0) Having defined the inputs
and outputs, we proceed to build the truth table for this code converter. The block diagram
depicts the inputs and output details.

The truth table, lists the values of the output (that is the excess-3 code) for all possible
combinations of the binary code. Note that, these codes are codes for decimal digits 0-9. In
other words, even though the 4 bits of the input can represent up to 16 different combinations,
ONLY 10 combinations are used to represent the 10 decimal digits. Thus, a total of 6 input
combinations are not likely to occur. Since these inputs will never occur, we use dont cares
for the corresponding output codes.

Truth Table for BCD to Excess-3 Code Converter


BCD Input

Excess 3 Output

Decimal

B3

B2

B
1

B0

E3

E2

E1

E0

All other inputs

10-15

As the procedure for simplification of a Boolean function suggests, we will minimize the four
output functions using K-maps. Thus we will be having four K-maps, one for each output
function. Each of these K-maps are given below

K-Map for E3

K-Map for E2

K-Map for E1

K-Map for E0

E3=B3+B2(B0+B1)

E2=B2B1+B2B0+B2B1B0
= B2(B1+B0)+B2B1B0
E2=B2(B1+B0)

The expressions for Excess-3 outputs (E3E2E1E0) can be implemented for terms of inputs
(B3B2B1B0) to form a BCD to XS-3 code converter circuit as below

You might also like