Digital Logic Design Week 2 Lecture 1
Digital Logic Design Week 2 Lecture 1
1
Binary Coding
Codes
2
Binary Coded Decimal
3
BCD Codes
Decimal BCD (8421)
0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
4
BCD Codes
Decimal BCD (8421)
Invalid Codes!
0 0000
1 0001 Decimal BCD (8421)
2 0010 10 1010
3 0011 11 1011
4 0100 12 1100
5 0101 13 1101
6 0110 14 1110
7 0111 15 1111
8 1000
9 1001
5
BCD (Cont.)
6
BCD (Cont.)
Representation of a decimal number with Binary Coded Decimals
7
Binary to BCD
• (1 0100)2 = (?)BCD
• (1001001)2 = (?)BCD
8
Binary to BCD
• (1 0100)2 = (14)BCD
• (1001001)2 = (49)BCD
9
BCD vs Binary
Tradeoffs between binary number and packed BCD (BCD coded
number)
10
BCD Addition Rules
Step 1 − Perform addition of two BCD numbers by following the rules of binary
addition.
Step 2 − If the result or sum is a 4-bit binary number which is less than or equal to 9,
then the sum is a valid BCD number.
Step 3 − If the sum is a 4-bit number that is greater than 9 or if a carry is generated,
then it is an invalid sum.
Step 4 − To obtain the corrected result/sum, add 6 (0110) to the 4-bit invalid sum. If a
carry is generated when 6 is added, then propagate and add this carry to the next 4-bit
group. This step is done to skip the six illegal BCD codes (i.e. 1010, 1011, 1100, 1101, 1110,
and 1111).
11
BCD Addition Example
12
BCD Addition Example 2
13
2421 Code
14
2421 Code
15
How to determine if a coding method is self
complementing?
16
Excess-3 Code
17
Excess 3 Code
18
Excess 3 Code Practice
Decimal to XS-3
• (24)10= (0101 0111)XS-3
• (658)10= (1001 1000 1011) XS-3
19
Is Excess-3 Self-Complementary?
20
Excess-3 Addition
• (984)10 + (599)10 in XS-3
• (27)10 + (39)10 in XS-3
Steps
For A+B in XS-3
1. Add each digit of A and B using binary addition
2. If carry then add it to the next bits and consider this bits as Invalid
3. Add 3 for Invalid bits and subtract 3 for others
4. If there is a carry in the end, simply write it as 0100
21
Gray Code
Unweighted code
22
Gray Code Table
23
Binary to Gray Code
• Step1 : Record the MSB as it is
• Step 2 : Add the MSB to the next bit, record the sum and neglect
the carry
• Step 3 : Repeat the process
24
Gray Code to Binary
25
Explore Yourself!
• BCD subtraction
• Excess 3 Subtraction
• Division of fractional numbers
Reference Link
Additional Link:
https://codescracker.com/computer-fundamental/bcd-excess-3-2421-gray-
code.htm
26
THANK YOU!
Reference:
Digital Logic and Computer Design. M. Morris Mano (1979).
27