Lecture 12 & 13 Dtm Codes)
Lecture 12 & 13 Dtm Codes)
Lecture 12 & 13 Dtm Codes)
(NBA Accredited)
Semester: Third
Course : Digital Techniques & Microprocessor
Course Code:22323
Chapter 1
Topic:
Codes(BCD, Gray, Excess-3 code
ASCII & EBCDIC Codes)
By : Trupti Dudhat
CODES
CODES
Types of codes
BCD codes
Excess-3 codes
Gray codes
ASCII codes
EBCDIC
0 0 0 0 0 0 0 0 0
1 0 0 0 1 0 0 0 1
2 0 0 1 0 0 0 1 0
3 0 0 1 1 0 0 1 1 Invalid Codes
4 0 1 0 0 0 1 0 0
5 0 1 0 1 0 1 0 1
6 0 1 1 0 0 1 1 0
7 0 1 1 1 0 1 1 1
8 1 0 0 0 1 0 0 0
9 1 0 0 1 1 0 0 1
10 1 0 1 0 0 0 0 1 0 0 0
0
11 1 0 1 1 0 0 0 1 0 0 0
1
12 1 1 0 0 0 0 0 1 0 0 1
0
13 1 1 0 1 0 0 0 1 0 0 1 Compiled by Ms.Trupti Dudhat
Binar Decimal BCD
y Number Code
Code
ABCD
0000 0 0000
0001 1
0010 V 2
a
0011 3
l
8 1000
5 010 1
13 1 101
Invalid BCD
13>9(Invalid BCD Adding 6 to the result
13 1 101
6 0110
1 0011
0001 0011
Compiled by Ms.Trupti Dudhat
1 3
BCD Addition
Case3:
(57)₁₀ + (26) ₁₀ Perform BCD Addition
57 0101 0111
58 0010 0110
83 0111 1101
7 13
(Valid BCD) (Invalid BCD)
13>9(Invalid BCD Adding 6 to the result
0111 1101
0000 0110
1000 0011
8 3
Compiled by Ms.Trupti Dudhat So, (57)₁₀ + (26) ₁₀=(83) ₁₀
Perform BCD Addition
1. (57)10 + (34)10 = (?)10
STEP 1 Convert the number into BCD
(57)10 0101 0111 (34)10 0011 0100
1 1 1 1
5 7 0 1 0 1 0 1 1 1
+ 3 4 0 0 1 1 0 1 0 0
9 1 1 0 0 0 1 0 1 1
valid invalid
100 000
1 1 1
1 1
1 0 0 0 1 0 1 1
+ 0 0 0 0 0 1 1 0
1 0 0 1 0 0 0 1
9 1
Compiled by Ms.Trupti Dudhat
Perform BCD Addition
2. (78)10 + (38)10 = (?)10
STEP 1 Convert the number into BCD
(78)10 0111 1000 (38)10 0011 1000
1 1 1 1
7 8 0 1 1 1 1 0 0 0
+ 3 8 0 0 1 1 1 0 0 0
1 1 6 1 0 1 1 0 0 0 0
invali invalid
000 000 011 d
1 1 1
1 1 0
1 0 1 1 0 0 0 0
+ 0 1 1 0 0 1 1 0
0 0 0 1 0 0 0 1 0 1 1 0
1 1 6
Compiled by Ms.Trupti Dudhat
Non-Weighted Codes
• These codes do not work of principle of positional weight.
We will consider two such codes
1. Excess-3 Codes
2. Gray Codes
13
14
• 4-bit code is obtained by adding binary 0011 to the natural BCD code of
the digit.
• Example - decimal 2 is coded as 0010 + 0011 = 0101 as Excess-3 code.
1 1 1 1 1 1 1 1
0 0 1 0 0 0 1 1 0 1 0 1 0 1 1 0
+ 0 0 1 1 0 0 1 1 + 0 0 1 1 0 0 1 1
0 Ms.Trupti
Compiled by 1 0 1 0 1 1 0
Dudhat 1 0 0 0 1 0 0 1
Q. Obtain the XS-3 code for (428)10
Decimal 4 2 8
1
BCD 0100 0010 1000
+3 0 0 1 1 0 01 1 0011
0111 0101 1011
16
2 4 7 . 6
17
0 0000 12 1100
1 0001 13 1101
3 0011 15 1111
2 0010 14 1110
6 0110 10 1010
7 0111 11 1011
5 0101 9 1001
4by Ms.Trupti
Compiled 0 1Dudhat
00 8 1000
BINARY TO GRAY CODE CONVERSION
B3 B2 B1
A B EXOR
B0
0 0 0
+ + +
0
1
1
0
1
1
1 1 0
G3 G2 G1
G0
G3 = B3 G2 = B2 EXOR B1
G2Compiled by Ms.Trupti Dudhat
= B3 EXOR B2 G2 = B1 EXOR B0
EXAMPLE 1
(1101)2 = (?)gray
A B EXOR
1 1 0 0 0 0 1
0 1 1
1 0 1
+ + + 1 1 0
1 0 1 1
(1101)2 = (1011)gray
Compiled by Ms.Trupti Dudhat
EXAMPLE 2
(1100101)2 = (?)gray
1 1 0 0
1 0 1
+ + + + + +
1 0 1 0
Compiled by Ms.Trupti Dudhat
1 1 1
GRAY TO BINARY CODE CONVERSION
G3 G2 A
G1B EXOR
0 0 0
G0 0 1 1
+ + +
1
1
0
1
1
0
G3 G2 G1
G0
(1011)gray = (?)2
1 0 1
1 + + +
A B EXOR
0 0 0
0 1 1
1 0 1
1 1 0
EXAMPLE 2
(1010111)gray = (?)2
1 0 1 0
1 1 1
+ + + + + +
1 1 0 0
1 0 1
Any Doubts?