0% found this document useful (0 votes)
6 views10 pages

Exp 2

Uploaded by

nileshmarathe166
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views10 pages

Exp 2

Uploaded by

nileshmarathe166
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 10

EXPERIMENT NO.

2
Design and implement Code Converters-Binary to Gray and
BCD to Excess-3
Title: Code Convertor

Problem Statement:
Design and implementation of 4-bit Code convertors.
i) Binary to Gray Code
ii) Gray to Binary Code
iii) BCD to Excess – 3 Code
iv) Excess-3 to BCD Code

IC’s Used:
IC 7404(Hex INV), 7432 (OR-gate), 7408 (AND-gate), 7486 (Ex-or gate)

Theory: There is a wide variety of binary codes used in digital systems. Some of these
codes are binary- coded -decimal (BCD), Excess-3, Gray, octal, hexadecimal, etc. Often it is
required to convert from one code to another. For example the input to a digital system
may be in natural BCD and output may be 7-segment LEDs. The digital system used may be
capable of processing the data in straight binary format. Therefore, the data has to be
converted from one type of code to another type for different purpose. The various code
converters can be designed using gates.
1) Binary Code:
It is straight binary code. The binary number system (with base 2) represents values using
two symbols, typically 0 and 1.Computers call these bits as either off (0) or on (1). The
binary code are made up of only zeros and ones, and used in computers to stand for
letters and digits. It is used to represent numbers using natural or straight binary form.
It is a weighted code since a weight is assigned to every position. Various arithmetic
operations can be performed in this form. Binary code is weighted and sequential code.
2) Gray Code:
It is a modified binary code in which a decimal number is represented in binary form in
such a way that each Gray- Code number differs from the preceding and the succeeding
number by a single bit. (E.g. for decimal number 5 the equivalent Gray code is 0111 and for
6 it is 0101. These two codes differ by only one bit position i. e. third from the left.)
Whereas by using binary code there is a possibility of change of all bits if we move from one
number to other in sequence (e.g. binary code for 7 is 0111 and for 8 it is 1000). Therefore
it is more useful to use Gray code in some applications than binary code. The Gray code is a
non-weighted code i.e. there are no specific weights assigned to the bit positions. Like
binary numbers, the Gray code can have any no. of bits. It is also known as reflected code.
Applications:
1. Important feature of Gray code is it exhibits only a single bit change from one code word
to the next in sequence. This property is important in many applications such as Shaft
encoders where error susceptibility increases with number of bit changes between
adjacent numbers in sequence.
2. It is sometimes convenient to use the Gray code to represent the digital data converted
from the analog data (Outputs of ADC).
3. Gray codes are used in angle-measuring devices in preference to straight forward binary
encoding.
4. Gray codes are widely used in K-map
The disadvantage of Gray code is that it is not good for arithmetic operation
Binary To Gray Conversion
1. Record the most significant bit as it is.
2. EX-OR this bit to the next position bit, record the resultant bit.
3. Record successive EX-ORed bits until completed.
4. Convert 0011 binary to Gray.

0 0 1 1 Binary code

+ + +

0 0 1 0 Gray code

(MSB) (LSB)

Fig. 1 Binary To Gray Conversion


Gray To Binary Conversion
1. The Gray code can be converted to binary by a reverse process.
2. Record the most significant bit as it is.
3. EX-OR binary MSB to the next bit of Gray code and record the resultant bit.
4. Continue the process until the LSB is recorded.
5. Convert 1011 Gray to Binary code.
1 0 1 1 Gray code

+ + +

1 1 0 1 Binary code

(MSB) (LSB)

Fig. 2 Gray To BinaryConversion


3) BCD Code:
Binary Coded Decimal (BCD) is used to represent each of decimal digits (0 to 9) with a 4-bit
binary code. For example (23)10 is represented by 0010 0011 using BCD code rather
than(10111)2 This code is also known as 8-4-2-1 code as 8421 indicates the binary weights
of four bits(23, 22, 21, 20). It is easy to convert between BCD code numbers and the familiar
decimal numbers. It is the main advantage of this code. With four bits, sixteen numbers
(0000 to 1111) can be represented, but in BCD code only 10 of these are used. The six code
combinations (1010 to 1111) are not used and are invalid.
Applications: Some early computers processed BCD numbers. Arithmetic operations can
be performed using this code. Input to a digital system may be in natural BCD and output
may be 7-segment LEDs.
It is observed that more number of bits are required to code a decimal number using BCD
code than using the straight binary code. However in spite of this disadvantage it is very
convenient and useful code for input and output operations in digital systems.

Fig. 3 BCD Coded Decimal Representation


EXCESS-3 Code:
Excess-3, also called XS3, is a non weighted code used to express decimal numbers. It can
be used for the representation of multi-digit decimal numbers as can BCD.The code for
each decimal number is obtained by adding decimal 3 and then converting it to a 4-bit
binary number. For e.g. decimal 2 is coded as 0010 + 0011 = 0101 in Excess-3 code. This is
self complementing code which means 1’s complement of the coded number yields 9’s
complement of the number itself. Self complementing property of this helps considerably in
performing subtraction operation in digital systems, so this code is used for certain
arithmetic operations.

BCD To Excess – 3 Code Conversion:


Convert BCD 2 i. e. 0010 to Excess – 3 code
For converting 4 bit BCD code to Excess – 3, add 0011 i. e. decimal 3 to the respective code
using rules of binary addition.
0010 + 0011 = 0101 – Excess – 3 code for BCD 2
Excess – 3 Code To BCD Conversion:
The 4 bit Excess-3 coded digit can be converted into BCD code by subtracting decimal value
3 i.e. 0011 from 4 bit Excess-3 digit.
e.g. Convert 4-bit Excess-3 value 0101 to equivalent BCD code.
0101-0011= 0010- BCD for 2

Design: A) Binary To Gray Code Conversion:


1) Truth Table:
INPUT (BINARY CODE) OUTPUT (GRAY CODE)
B3 B2 B1 B0 G3 G2 G1 G0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 0 0 0 1 1
0 0 1 1 0 0 1 0
0 1 0 0 0 1 1 0
0 1 0 1 0 1 1 1
0 1 1 0 0 1 0 1
0 1 1 1 0 1 0 0
1 0 0 0 1 1 0 0
1 0 0 1 1 1 0 1
1 0 1 0 1 1 1 1
1 0 1 1 1 1 1 0
1 1 0 0 1 0 1 0
1 1 0 1 1 0 1 1
1 1 1 0 1 0 0 1
1 1 1 1 1 0 0 0

2) K-Map For Reduced Boolean Expressions Of Each Output:


Fig. 4 K-Map For Reduced Boolean Expressions Of Each Output (Gray
Code)
3) Circuit Diagram:

Fig. 5 Logic Diagram for Binary to Gray Code Conversion


4) Hardware Requirements Table:

GATE Quantity IC Quantity

XOR 3 7486 1

B) Gray To Binary Code Conversion: Truth Table


INPUT (GRAY CODE) OUTPUT (BINARY CODE)
G3 G2 G1 G0 B3 B2 B1 B0
0 0 0 0 0 0 0 0
0 0 0 1 0 0 0 1
0 0 1 1 0 0 1 0
0 0 1 0 0 0 1 1
0 1 1 0 0 1 0 0
0 1 1 1 0 1 0 1
0 1 0 1 0 1 1 0
0 1 0 0 0 1 1 1
1 1 0 0 1 0 0 0
1 1 0 1 1 0 0 1
1 1 1 1 1 0 1 0
1 1 1 0 1 0 1 1
1 0 1 0 1 1 0 0
1 0 1 1 1 1 0 1
1 0 0 1 1 1 1 0
1 0 0 0 1 1 1 1

2) K-Map For Reduced Boolean Expressions Of Each Output:


Fig. 6 K-Map For Reduced Boolean Expressions Of Each Output (Binary Code)
3) Circuit Diagram:

Fig. 7 Logic Diagram for Gray to Binary Code Conversion

4) Hardware Requirements Table:


GATE Quantity IC Quantity

XOR 3 7486 1

Conclusion:

Hence we have studied all the operations and implementation of code convertor.

You might also like