Lecture 12 & 13 Dtm Codes)

Download as pptx, pdf, or txt
Download as pptx, pdf, or txt
You are on page 1of 28

Program: Information technology

(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

Compiled by Ms.Trupti Dudhat


BCD (Binary-Coded Decimal) code

• It says represent each decimal digit with 4 bit binary code.


• BCD has ten valid codes from 0 to 9 (0000 to 1001).
• It has 6 invalid codes i.e. 1010, 1011, 1100, 1101, 1110, and 1111.

• Example - (37)10 is represented as 0011 0111 using BCD code, rather


than (100101)2 in straight binary code.
• BCD codes are easy to understand and represent.
• BCD code requires more bits than straight binary code.

Compiled by Ms.Trupti Dudhat


Decimal Binary BCD
8 4 2 1

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

BCD table 0100


0101
i
d
4
5
0110 6
B
0111 C 7
1000 D 8
I
1001 9 n 1001
1010 10 v 0001
a 0000
1011 11 li 0001
d 0001
B
1100 12 0001
Compiled by Ms.Trupti Dudhat C
0010
D
Rules for BCD addition

Sum <= 9 Sum > 9 Sum <= 9


and carry = and carry = and carry =
0 0 1
Valid Invalid Invalid

Add zero Add Six Add Six


(0000) (0110) (0110)

Compiled by Ms.Trupti Dudhat


Binary Decimal BCD
BCD Addition Code
ABCD
Number Code

Case1: 0000 0 0000


0001 1
(4)₁₀ + (5) ₁₀ Perform BCD Addition
0010 2
0011 3
0100 4
4 0 100 0101 5
5 0 101 0110 6
9 1 001
0111 7
1000 8
Valid BCD 1001 9 1001
1010 10 0001
0000
so,(4)₁₀ + (5) ₁₀=(9) ₁₀ 1011 11 0001
0001
1100 12 0001
Compiled by Ms.Trupti Dudhat
0010
1101 13 0001
BCD Addition
Case2:
(8)₁₀ + (5) ₁₀ Perform BCD Addition

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

Compiled by Ms.Trupti Dudhat


Excess-3 Codes Decimal BCD Excess-3
0 0000 0011
• The excess-3 code (or XS3) is a
1 0001 0100
non-weighted code used to
express code used to express 2 0010 0101
decimal numbers. 3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100

14

Compiled by Ms.Trupti Dudhat


Excess-3 code

• 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.

Find excess 3 code for the following

1. (23)10 = (?)excess-3 2. (56)10 = (?)excess-3

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

Compiled by Ms.Trupti Dudhat


Q. Convert the Decimal Number
into Excess-3 code (247.6)10

2 4 7 . 6

17

Compiled by Ms.Trupti Dudhat


Gray Code
 The Gray Code is a sequence of binary number systems, which is also known as reflected binary code.
 Gray code has property that two successive numbers differ in only one bit.
 A 4 bit Gray code sequence is as follows

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

Compiled by Ms.Trupti Dudhat


EXAMPLE 1

(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

Compiled by Ms.Trupti Dudhat


(1010111) = (1100101)
ASCII Code
 The ASCII stands for American Standard Code for Information Interchange.
 The ASCII code is an alphanumeric code used for data communication in digital
computers.
 The ASCII is a 7-bit code capable of representing 2 7 or 128 number of different
characters.
 The ASCII code is made up of a three-bit group, which is followed by a four-bit code.
 The ASCII Code is a 7 or 8-bit alphanumeric code.
 This code can represent 127 unique characters.
 The ASCII code starts from 00h to 7Fh. In this, the code from 00h to 1Fh is used for
control characters, and the code from 20h to 7Fh is used for graphic symbols.
 The 8-bit code holds ASCII, which supports 256 symbols where math and graphic
symbols are added.
 The range of the extended ASCII is 80h to FFh.

Compiled by Ms.Trupti Dudhat


EBCDIC

Extended binary coded decimal interchange code (EBCDIC)


 It is an 8-bit binary code for numeric and alphanumeric characters.
 It was developed and used by IBM.
 It is a coding representation in which symbols, letters and numbers
are presented in binary language.

Compiled by Ms.Trupti Dudhat


Queries
Session

Any Doubts?

Compiled by Ms.Trupti Dudhat


Thank you

You might also like