Digital Logic Design
Dr. P. Chandrashekar
Professor
Dept. of ECE
1
Introduction
Binary codes
Code Conversion
2
List the course outcome / Topic outcome
Name of the Topic
Topic Learning Outcome Course Outcome
covered
Understand Binary
codes, BCD code and its Outline binary addition,
properties subtraction, 2’s
Binary codes Representation of Unit complement
Code Conversion distance code, representation and
alphanumeric codes, operations for doing
and error detecting and computations
correcting codes
3
Name of the topic: Binary addition, Subtraction, Complementary
Representation and operations
Students will be able to do:
1 Understanding Binary codes, BCD code and its properties
2 Understanding Unit distance code, alphanumeric codes, and error
detecting and correcting codes
4
Binary Codes
Classification of binary codes
1. Weighted codes
2. Non-weighted codes
3. Reflective codes
4. Sequential codes
5. Alphanumeric codes
6. Error detecting and correcting codes
5
1. Weighted codes
Each digit position of the number represents a specific weight
Binary
BCD
• 8,4,2,1 2,4,2,1 3,3,2,1 5,2,1,1
• 5,3,1,1 5,4,2,1 6,3,1,1 7,4,2,1
• 7,4,-2,-1 8,4,-2,-1
Decimal BCD Excess-3 84-2-1 2421 5211
Number 8421
0 0000 0011 0000 0000 0000
1 0001 0100 0111 0001 0001
2 0010 0101 0110 0010 0011
3 0011 0110 0101 0011 0101
4 0100 0111 0100 0100 0111
5 0101 1000 1011 1011 1000
6 0110 1001 1010 1100 1010
7 0111 1010 1001 1101 1100
8 1000 1011 1000 1110 1110
9 1001 1100 1111 1111 1111
6
2. Non-weighted codes
Not assigned with any weight to each digit position of the
number Decimal Binary Excess-3 Gray
Excess-3 Number Code Code
0 0000 0011 0000
Gray
1 0001 0100 0111
2 0010 0101 0110
3 0011 0110 0101
4 0100 0111 0100
5 0101 1000 1011
6 0110 1001 1010
7 0111 1010 1001
8 1000 1011 1000
9 1001 1100 1111
7
3. Reflective codes
A code is said to be reflective when code for 9 is complement
for the code for 0, and so is for 8 and 1 codes, 7 and 2, 6 and
3, 5 and 4.
Codes 2421, 5211, and excess-3 are reflective, whereas the
8421 code is not.
Decimal BCD Excess-3 84-2-1 2421 5211
Number 8421
0 0000 0011 0000 0000 0000
1 0001 0100 0111 0001 0001
2 0010 0101 0110 0010 0011
3 0011 0110 0101 0011 0101
4 0100 0111 0100 0100 0111
5 0101 1000 1011 1011 1000
6 0110 1001 1010 1100 1010
7 0111 1010 1001 1101 1100
8 1000 1011 1000 1110 1110
9 1001 1100 1111 1111 1111
8
4. Sequential codes
A code is said to be sequential when two subsequent
codes, seen as numbers in binary representation, differ by
one.
The 8421 and Excess-3 codes are sequential, whereas the
2421 and 5211 codes are not.
Decimal BCD Excess-3 84-2-1 2421 5211
Number 8421
0 0000 0011 0000 0000 0000
1 0001 0100 0111 0001 0001
2 0010 0101 0110 0010 0011
3 0011 0110 0101 0011 0101
4 0100 0111 0100 0100 0111
5 0101 1000 1011 1011 1000
6 0110 1001 1010 1100 1010
7 0111 1010 1001 1101 1100
8 1000 1011 1000 1110 1110
9 1001 1100 1111 1111 1111
9
5. Alphanumeric codes
These codes are used to encode the characteristics of alphabet in
addition to the decimal digits.
It is used for transmitting data between computers & its I/O
device such as printers, keyboards & video display terminals.
Popular modern alphanumeric codes are ASCII code (American
Standard Code for Information Interchange) & EBCDIC
(Extended Binary Coded Decimal Interchange Code).
10
6. Error detecting and correcting codes
When binary data is transmitted & processed, it is susceptible to noise
that can alter or distort its contents.
The 1‘s may get changed to 0‘s & 1‘s
Because digital systems must be accurate to the digit, error can pose a
problem
Several schemes have been devised to detect the occurrence of a single
bit error in a binary word, so that whenever such an error occurs the
concerned binary word can be corrected & retransmitted
Example:
Parity codes
Hamming codes
11
Binary Coded Decimal number system (8,4,2,1)
Decimal BCD
Binary coded decimal
0 0000
Only encodes ten digits from 0 to 9 1 0001
2 0010
BCD is a weighted code
3 0011
The weights are 8,4,2,1 4 0100
5 0101
There are six invalid codes 6 0110
7 0111
1010, 1011, 1100, 1101, 1110, 1111
8 1000
Example 13 (0001 0011)BCD 9 1001
12
BCD (8,4,2,1)
13
BCD Addition
There are 6 illegal combinations 1010, 1011, 1100, 1101, 1110, 1111 in these
codes, they are not part of the 8421 BCD code system
It is individually adding the corresponding digits of the decimal no's expressed
in 4 bit binary groups starting from the LSD
If there is no carry & the sum term is not an illegal code, no correction is
needed
If there is a carry out of one group to the next group or if the sum term is an
illegal code then 610 (0110) is added to the sum term of that group & the
resulting carry is added to the next group
14
BCD Addition
• Perform decimal additions in 8421 code
(a) 25 + 13
(b) 679.6 + 536.8
15
BCD Subtraction using 9’s & 10’s compliment
• Perform decimal subtraction in 8421 code
(a) 305.5 – 168.8
16
BCD Subtraction
• Perform decimal subtraction in 8421 code
(a) 38 - 15
(b) 206.7 - 147.8
17
Other 4-bit BCD codes
18
2. Non-weighted codes
Not assigned with any weight to each digit position of the
number
Decimal Binary Excess-3 Gray
Excess-3 Number Code Code
Gray 0 0000 0011 0000
1 0001 0100 0001
2 0010 0101 0011
3 0011 0110 0010
4 0100 0111 0110
5 0101 1000 0111
6 0110 1001 0101
7 0111 1010 0100
8 1000 1011 1100
9 1001 1100 1101
19
Excess-3
Derived from the natural BCD code by adding 3 to each coded
Decimal BCD Excess-3
number. Number 8421 BCD + 0011
0 0000 0011
1 0001 0100
2 0010 0101
3 0011 0110
4 0100 0111
5 0101 1000
6 0110 1001
7 0111 1010
8 1000 1011
9 1001 1100
Example: 13 (0001 0011)BCD (0100 0110)Excess-3
20
Gray codes
Unweighted (not an arithmetic Decimal Binary Gray
Number Code Code
code). 0 0000 0000
Only a single bit change from one 1 0001 0001
2 0010 0011
code number to the next. 3 0011 0010
4 0100 0110
Unit distance code, Cyclic codes or 5 0101 0111
reflected code. 6 0110 0101
7 0111 0100
Useful for error detection. 8 1000 1100
9 1001 1101
21
Binary to Gray codes
Convert (1011)2 to gray
22
Gray codes
23
Problems
1. Convert the following code to Gray code
1 0 1 1 0
2. Give the binary, BCD, excess-3, gray code
representations of decimal numbers: 5, 8 , 14
3. Convert each of the following decimal numbers to
excess-3 code
i. (18)10
ii. (56)10
4. Represent the decimal number 1234 in
(i) Binary (ii) BCD (iii) Excess-3 code and (iv) Gray code
24
6. Error detecting and correcting codes
When binary data is transmitted & processed, it is susceptible to noise
that can alter or distort its contents.
The 1‘s may get changed to 0‘s & 1‘s
Because digital systems must be accurate to the digit, error can pose a
problem
Several schemes have been devised to detect the occurrence of a single
bit error in a binary word, so that whenever such an error occurs the
concerned binary word can be corrected & retransmitted
Example:
Parity codes
Hamming codes
25
Parity
• A parity bit is used for the purpose of detecting errors during
transmission of binary information
• A parity bit is an extra bit included with a binary message to make
the number of 1s either odd or even
• If odd no. of 1s odd parity (1 1 1 0)
• If even no. of 1s even parity (1 0 0 1)
• Transmitted code has two parts
1. Parity bit
2. Message bits
26
Hamming Code: Generation
Message 1 0 0 1
Number of Parity bits: 2P ≥ m + p +1
m: number of message bits
p: number of parity bits
Bit Designation P1 P2 M1 P3 M2 M3 M4
Bit Position 1 2 3 4 5 6 7
Binary Position 001 010 011 100 101 110 111
Message Bits 1 0 0 1
Parity Bits 0 0 1
The Hamming Code is : 0 0 1 1 0 0 1
P1=3,5,7:P2=3,6,7:P3=5,6,7
27
Hamming Code: Error Detection & Correction
Code received: 0 0 1 0 0 0 1
Bit Designation P1 P2 M1 P3 M2 M3 M4
Bit Position 1 2 3 4 5 6 7
Binary Position 001 010 011 100 101 110 111
Message Bits 0 0 1 0 0 0 1
Parity Bits
P1 =0 P2 =0 P3 =1
P3 P2 P1
1 0 0 corresponds to decimal ‘4’. The error is in 4th bit.
P1=3,5,7:P2=3,6,7:P3=5,6,7
28
Generation of Hamming code
Message: 0 1 0 1
Bit P1 P2 M1 P3 M2 M3 M4
designation
Bit Position 1 2 3 4 5 6 7
Binary 001 010 011 100 101 110 111
Position
Message Bits 0 1 0 1
Parity Bits 0 1 0
The Hamming Code is 0 1 0 0 1 0 1
29
Error Detection & Correction
I. Detection of whether received code is correct or not
0 0 1 0 0 0 1
i. Check if received code is correct.
ii. If there is an error, determine which bit has error.
iii. Determine correct code.
30
Procedure
The Hamming Code received : 0 0 1 0 0 0 1
Bit P1 P2 M1 P3 M2 M3 M4
designation
Bit Position 1 2 3 4 5 6 7
Binary 001 010 011 100 101 110 111
Position
Message Bits 0 0 1 0 0 0 1
Parity Bits
31
Procedure
The Hamming Code received : 0 0 1 0 0 0 1
Parity bits: P1= 0 P2=0 P3=1
P1 P2 P3 = 0 0 1 corresponds to decimal ‘4’. The error is in
4th bit.
Bit P1 P2 M1 P3 M2 M3 M4
designation
Bit Position 1 2 3 4 5 6 7
Binary 001 010 011 100 101 110 111
Position
Message Bits 0 0 1 0 0 0 1
Parity Bits 0 0 1
Correct Message : 0 0 1 1 0 0 1
32
12 bit Hamming code
Message: 0 1 0 1 0 0 0 1
Bit P1 P2 M1 P3 M2 M3 M4 P5 M5 M6 M7 M8
designation
Bit Position 1 2 3 4 5 6 7 8 9 10 11 12
Message
Bits
P1=3,5,7,9,11
P2=3,6,7,10,11
P4=5,6,7,12
P8=9,10,11,12
33