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

Degital Logic Design Lec 3

The document discusses various coding systems used in digital logic design, including Binary Coded Decimal (BCD), Excess-3 Code, Gray Code, and ASCII. It explains the classification of codes into weighted, non-weighted, reflective, sequential, alphanumeric, and error detecting/correcting codes. Additionally, it covers the conversion processes between decimal and BCD, as well as BCD addition techniques.

Uploaded by

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

Degital Logic Design Lec 3

The document discusses various coding systems used in digital logic design, including Binary Coded Decimal (BCD), Excess-3 Code, Gray Code, and ASCII. It explains the classification of codes into weighted, non-weighted, reflective, sequential, alphanumeric, and error detecting/correcting codes. Additionally, it covers the conversion processes between decimal and BCD, as well as BCD addition techniques.

Uploaded by

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

ECN1001-Digital Logic

Design
Igbafe Orikumhi Ph.D.,

Department of Electronics and


Computer Engineering, Hanyang
University

oigbafe2@hanyang.ac.kr

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D.


Contents
Codes Introduction

Binary Coded Decimal

Excess-3 Code

Gray Code

ASCII Code
Codes

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 3


Introduction

• Codes are used extensively with computers to define


alphanumeric characters and other information.
• Information Types
• Numeric
• Must represent range of data needed
• Very desirable to represent data such that simple, straightforward computation
for common arithmetic operations permitted
• Tight relation to binary numbers
• Non-numeric
• Greater flexibility since arithmetic operations not applied.
• Not tied to binary numbers

Codes are group of symbols

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 4


Introduction

0101010001 0101010001

Transmitter Receiver

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 5


Non-numeric Binary Codes

• Given n binary digits (called bits), a binary code is a mapping


from a set of represented elements to a subset of the 2n binary
numbers.
• Example: A binary code for the seven colors of the rainbow

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 6


Example of Codes

• Binary Coded Decimal (8421 Code, 2421 Code)

• Excess-3 Codes

• Grey Codes,

• American Standard Code for information Interchange (ASCII)

• Hamming Codes

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 7


Classification of Codes
codes

Weighted Non-weighted Reflective Sequential Alphanumeric Error detecting and


codes codes codes codes codes correcting codes

• Weighted codes e.g. Binary Coded Decimal, 8421, 2421, etc.


• Non-weighted codes e.g. Gray codes, XS-3
• Reflective codes (self complementing codes) e.g. XS-3, 2421
• Sequential codes (one binary number greater than the preceding
code) e.g. 8421, XS-3
• Alphanumeric codes e.g. ASCII
• Error detecting and correcting codes e.g. Hamming code

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 8


Binary Coded Decimal
(BCD)

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 9


Binary Coded Decimal

• BCD is a way to express each of the decimal digits with a binary


code.

• There are only ten code groups in the BCD system making very
easy to convert to decimal and vice-versa

• The BCD provides an excellent interface to binary systems.


• Keypad

• Digital readouts

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 10


Binary Coded Decimal
Decimal Binary Number
Number
0 0 0 0 0
• It’s a type of BCD code 1 0 0 0 1
2 0 0 1 0
• Binary coded decimal means that each 3 0 0 1 1
4 0 1 0 0
decimal digits is represented by a binary 5 0 1 0 1 Valid BCD
6 0 1 1 0 code
code of four bits 7 0 1 1 1
8 1 0 0 0
• The designation indicates the binary 9 1 0 0 1
10 1 0 1 0
weights of the four bits () 11 1 0 1 1
12 1 1 0 0
• The main advantage of this codes is its 13 1 1 0 1
14 1 1 1 0 Invalid BCD
ease of conversion 15 1 1 1 1 code

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 11


Binary Coded Decimal
Decimal Binary Number
Number
0 0 0 0 0
• With four bits, sixteen numbers (0000 1 0 0 0 1
2 0 0 1 0
through 1111) can be represented 3 0 0 1 1
4 0 1 0 0
• However in 8421 codes, only ten of these 5 0 1 0 1 Valid BCD
6 0 1 1 0 code
are used 7 0 1 1 1
8 1 0 0 0
• The six codes combination that are not 9 1 0 0 1
10 1 0 1 0
used are 1010, 1011, 1100, 1110 and 11 1 0 1 1
12 1 1 0 0
1111 13 1 1 0 1
14 1 1 1 0 Invalid BCD
• To express any decimal number in BCD, 15 1 1 1 1 code
simply replace each decimal digit with the
appropriate 4-bit code
ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 12
Binary Coded Decimal
Weight
8 4 2 1
• Recall that 159 is a decimal number with 0 0 0 0 0
3 decimal digits 1 0 0 0 1
• BCD codes have positional wights 2 0 0 1 0
associated with the binary codes. 3 0 0 1 1
• An example is 8-4-2-1 code 4 0 1 0 0
Valid BCD
5 0 1 0 1
code
6 0 1 1 0
• Example: Convert the decimal number
13 to BCD 7 0 1 1 1
8 1 0 0 0
1 3
9 1 0 0 1
0001 0011

• Answer in BCD

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 13


Conversion of Decimal to BCD

• Example: Convert the decimal number


189 to BCD Weight
8 4 2 1
0 0 0 0 0
• Answer in BCD 1 0 0 0 1
2 0 0 1 0
1 8 9 3 0 0 1 1
0001 1000 1001 4 0 1 0 0
Valid BCD
5 0 1 0 1
code
6 0 1 1 0
7 0 1 1 1
• Practice Question: Convert the decimal 8 1 0 0 0
number 561 to BCD 9 1 0 0 1

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 14


Conversion of BCD to Decimal
Number
• Example: Convert the BCD numbers and
0101010110 to decimal Weight
8 4 2 1
0 0 0 0 0
• Answer starting with the LSB group the 1 0 0 0 1
number in 4 bits and convert. Append 0 2 0 0 1 0
as the MSB if required 3 0 0 1 1
0001 0100
4 0 1 0 0
1 4 Valid BCD
5 0 1 0 1
code
0001 0101 0110 6 0 1 1 0
1 5 6 7 0 1 1 1
8 1 0 0 0
9 1 0 0 1
and 0101010110 in BCD are equivalent to
14 and 156 in decimal respectively

• Practice Question: Convert the number


11101100011 to Decimal
ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 15
Comparing Binary and BCD

• Example: Convert the decimal number


145 to binary and BCD Weight
8 4 2 1
0 0 0 0 0
• 145 in binary is 1 0 0 0 1
2 0 0 1 0
Weight 3 0 0 1 1
128 64 32 16 8 4 2 1
4 0 1 0 0
145 1 0 0 1 0 0 0 1 Valid BCD
5 0 1 0 1 code
6 0 1 1 0
145 in BCD is 000101000101 7 0 1 1 1
8 1 0 0 0

BCD requires more bits to represent a 9 1 0 0 1

decimal number compared to binary


number Hence, it is less efficient.
Arithmetic operation is also more
complicated for BCD

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 16


BCD Addition

To add binary number, we must take note of the following


• If sum 9 and final carry is 0; then the answer is correct

• If sum 9 and final carry is 1; the answer is incorrect, we must correct it


by adding 6 (0110) to the answer

• If sum 9 and final carry is 0; the answer is incorrect, we must correct it


by adding 6 (0110) to the answer

• Example: perform the BCD addition of the following decimal number 5


+2
0101
• Answer:
0010

0111
(0111 is 7) sum < 9

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 17


BCD Addition

• Example: perform the BCD addition of the following decimal number 4


+8
• Answer: 1000
+¿ 0100

1100
(1100 is 12) sum > 9 with final carry =0
hence the answer is incorrect, we must
add 6 (0110 to correct the result)

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 18


BCD Addition

• Example: perform the BCD addition of the following decimal number 4


+8
• Answer: 1000
+¿ 0100

1100
(1100 is 12) sum > 9 with final carry =0
+¿ 0110
hence the answer is incorrect, we must
add 6 (0110 to correct the result)
10010 (10010 is the BCD representation of 12)

• Example: perform the BCD addition of the following decimal number 8


+9 1000

1001

10001
0110

10111 (10111 is the BCD representation of 17)

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 19


BCD Addition

• Example: perform the BCD addition of the following decimal number


57+26
01010111 (57) In decimal
+¿ 00100110 (26) In decimal
01111101
(7) and (13) In decimal. 13 is greater than 9 hence add 6
+¿ 0110
10000011 (83) In decimal

• Practice question: perform the BCD addition of the following decimal


number
(1) 3+2 (2) 8+6 (3) 78+57

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 20


BCD 2421 code

• We can construct the 2421 BCD code using the self complementing properties as
follows Weight
2 4 2 1
0 0 0 0 0
1 0 0 0 1
2 0 0 1 0
3 0 0 1 1
4 0 1 0 0
5 1 0 1 1
6 1 1 0 0
7 1 1 0 1
8 1 1 1 0
9 1 1 1 1

• Practice Questions:
1. Convert the decimal number 89 to BCD using the 2421 code and the 8421
code
2. A transmitted signal is encoded with a BCD 2421 encoder, if the code at the
receiver
ECN1001-Digital Logic Design is 01001100101, what is thePh.D.
© Igbafe Orikumhi, decimal equivalent? What will be the
21
Excess-3 Codes

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 22


Excess-3 Code

• To convert a decimal number to excess 3 code, perform the following


steps
Convert the decimal Add 3 (0011) to the The result is Excess-3
to BCD 8421 code BCD code code
BCD 8421 Excess-3 code
BCD code (add 0011)
0 0 0 0 0 0 0 1 1
1 0 0 0 1 0 1 0 0 XS-3 code is self
2 0 0 1 0 0 1 0 1 complementary. It is
3 0 0 1 1 0 1 1 0 the only unweighted
4 0 1 0 0 0 1 1 1 code which is self
5 0 1 0 1 1 0 0 0 complementary
6 0 1 1 0 1 0 0 1
7 0 1 1 1 1 0 1 0
8 1 0 0 0 1 0 1 1
9 1 0 0 1 1 1 0 0

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 23


Example-Excess-3 Code

• Example: convert the decimal number 45 to Excess-3 code

• Solution: Step 1: Convert 45 in decimal to BCD


4 5 Practice Question
0100 0101 Obtain the Excess-3
code for the following
Step 2: Add 3 (0011) to each group of the BCD
4 5 (1) 16
0100 0101
(2) 23
(3) 678
+¿ 0011 0011
0111 1000

• Example: convert the decimal number 498 to Excess-3 code


4 9 8
0100 1001 1000
+¿ 0011 0011 0011
0111 1100 1011

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 24


Addition of Excess-3 Code

• Example: Add the following excess-3 codes numbers 19+17

• Rule: When the final carry of any group is 1, add 0011 (3) to the group. If the
final carry is 0, subtract 0011 (3) from the group
0100 1100 1 9
+¿ 0100 1010 +¿ 1 7
1001 0110 3 6
− 0011 0011 +¿ +¿ 3 3
0110 1001 6 9

• Practice Example: Add the following excess-3 code


(1) 6+7
(2) 567+234
(3) 91+30
ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 25
Gray Codes

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 26


Gray Codes

• Gray code is a binary numeral system where two successive values


differ in only one bit
• Gray codes is names after Frank Gray who invented the code
• Frank Gray was a physicist in AT&T Bell Lab. He made numerous invention in television

• Gray codes are sometimes referred to as reflected Binary code (RBC)


• They are sometimes called unit distance codes or minimum error codes
or cyclic codes
• They are also unweighted codes

Binary numbers are converted into Gray code to reduce switching operation

Gray codes are widely use to facilitate error correction in digital


communication such as Cable TV systems

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 27


Gray Codes

• Gray code is a binary numeral system where two successive values

Useful to reduce
switching operation

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 28


Binary to Gray Codes Conversion

• Step 1: Write down the MSB of the binary code as it is


• Step 2: Add the MSB to the next significant bit record the sum and
neglect the carry
• Repeat the process

• Example: convert the binary number


0110 to Gray code
0 1 1 0
+¿0 +¿1 +¿
1
0 1 0 1

• Example: convert the binary number 1110 Practice Question


to Gray code Convert the following binary
1 1 1 0 number to Gray code
+¿1 +¿1 +¿
1
(1) 0011
1 0 0 1
(2) 0111
(3) 1010
ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 29
Gray to Binary Conversion

• Step 1: Write down the MSB of the binary code as it is


• Step 2: Add the MSB to the next significant bit of the gray code
record the sum and neglect the carry
• Repeat the process

• Example: convert the Gray code


0101 to Binary
0 1 0 1
+¿0 +¿1 +¿
1
+¿
0 1 1 0

• Example: convert the Gray code 1110 Practice Question


to a1binary number Convert the following Gray
1 1 0 code number to Binary
+¿1 +¿0 +¿
1
(1) 1100
1 0 1 1
(2) 1000
(3) 1111
ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 30
The Optical Shaft Encoder

• How does the shaft encoder work?


• The encoder disk contains opaque and clear areas.
• Opaque represents a 0 and clear a 1. Light shining through each ring of the encoder
corresponding to a bit of the code strikes a sensor to produce a 0 or a 1.

111 000 100 000

B 0

B 1

001 101 001


110
B 2

G 2
G 1

111 G 0
010 011
101

100 011 110 010

(a) Binary Code for Positions 0 through 7 (b) Gray Code for Positions 0 through 7

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 31


The Optical Shaft Encoder
• For the binary code, what codes may be produced if the shaft position lies
between codes for 3 and 4 (011 and 100)?
• In addition to the correct code, either 011 or 100, the codes 000, 010, 001, 110,
101, or 111 can be produced.
• Is this a problem? Answer: Yes, the shaft position can be completely
UNKNOWN!
111 000 100 000

B 0

B 1

001 101 001


110
B 2

G 2
G 1

111 G 0
010 011
101

100 011 110 010

(a) Binary Code for Positions 0 through 7 (b) Gray Code for Positions 0 through 7

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 32


The Optical Shaft Encoder
• For the Gray code, what codes may be produced if the shaft position lies
between codes for 3 and 4 (010 and 110)?
• Only the correct codes, either 010 or 110
• Is this a problem? No, the shaft position is known to be either 3 or 4 which
is OK since it is halfway in between.
111 000 100 000

B 0

B 1

001 101 001


110
B 2

G 2
G 1

111 G 0
010 011
101

100 011 110 010

(a) Binary Code for Positions 0 through 7 (b) Gray Code for Positions 0 through 7

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 33


ASCII Codes

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 34


Alphanumeric Codes

• These are codes that represent numbers and alphabetic characters


(letters).

• These codes however could be symbols and various instructions necessary


for conveying information

• At least it most represent 10 decimals and 26 letters for a total of 36

• These requires then six bits in each code combination because five bits
are insufficient

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 35


ASCII Codes

• ASCII is an abbreviation for American Standard Code for Information


Interchange

• Most keyboards are standardized with the ASCII

• When you enter a letter, a number or control command the corresponding


ASCII code goes into the computer

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 36


ASCII Codes

• ASCII has 128 characters and symbols represented by 7 bit binary code.

• It can be considered 8 bit code with the MSB 0.

• The first 32 ASCII characters are non-graphics used only for control
purposes

• The other characters been decimal, alphabets punctuation signs and other
commonly used symbols

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 37


Extended ASCII Codes

• In Addition to the 128 standard ASCII characters, there are additional 128
characters that were adopted by IBM in their PCS

• The extended ASCII characters are represented by an 8-bit code series


from hexadecimal 80 to hexadecimal FF

• The extended ASCII contains characters in the following categories

• Foreign alphabetic characters, foreign currency symbols, greek letters,


mathematical symbols, drawing characters, bar graphing etc..

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 38


ASCII Codes

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 39


ASCII Example

• Example: Determine the binary ASCII codes that are entered from the
computer’s Keyboard when the following BASIC program statement is
typed in, also express each code in Hexadecimal.
20 PRINT “A=”;X
• Solution: Practice Question:
Determine the binary
ASCII codes that is
required for the
following program
statement and express
them in hexadecimal

“80 Test Print”

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 40


Questions?

ECN1001-Digital Logic Design © Igbafe Orikumhi, Ph.D. 41

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy