Binary Codes
Conversion or Coding?
• Do NOT mix up conversion of a decimal number to a binary number
with coding a decimal number with a BINARY CODE.
• 1310 = 11012 (This is conversion)
• 13 0001|0011 (This is coding)
Binary Coded Decimal (BCD)
• The BCD code is the 8,4,2,1 code.
• 8, 4, 2, and 1 are weights
• BCD is a weighted code
• This code is the simplest, most intuitive binary code for decimal digits
and uses the same powers of 2 as a binary number, but only encodes
the first ten values from 0 to 9.
BCD Arithmetic
Given a BCD code, we use binary arithmetic to add the digits:
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
Note that the result is MORE THAN 9, so must be
represented by two digits!
To correct the digit, add No. 6
8 1000 Eight
+5 +0101 Plus 5
decimal adjust
13 1101 is 13 (> 9)
+0110 so add 6
carry = 1 0011
0001 | 0011 Final answer (two digits)
BCD Addition
BCD Addition(Contd…)
• Add 2905BCD to 1897BCD
0001 1000 1001 0111
+ 0010 1001 0000 0101
• 0001 1000 1001 0111
• + 0010 1001 0000 0101
• 0100 10010 1010 1100
• + 0000+ 0110+ 0110+ 0110
• 0100 1000 0000 0010
• Ans: 4802
BCD code for 2905 : 0010 1001 0000 0101
BCD code for 1897 : 0001 1000 1001 0111
Addition : 0011 10001 1001 1100
If Invalid BCD then add 6 : 0110 0110
Addition : 0011 10111 1001 10010
Remaining bits except carry : 0011 0111 1001 0010
Carry : 1 1
Addition : 0100 0111 1010 0010
If Invalid BCD then add 6 : 0110
Addition : 0100 0111 10000 0010
Remaining bits except carry : 0100 0111 0000 0010
Carry : 1
Addition : 0100 1000 0000 0010
BCD value : 4 8 0 2
Excess 3 Code and 8, 4, –2, –1 Code
Decimal Excess 3 8, 4, –2, –1
0 0011 0000
1 0100 0111
2 0101 0110
3 0110 0101
4 0111 0100
5 1000 1011
6 1001 1010
7 1010 1001
8 1011 1000
9 1100 1111
DECIMAL CODES - Binary Codes for Decimal
Digits
Decimal 8,4,2,1 Excess3 8,4,-2,-1 Gray
0 0000 0011 0000 0000
1 0001 0100 0111 0100
2 0010 0101 0110 0101
3 0011 0110 0101 0111
4 0100 0111 0100 0110
5 0101 1000 1011 0010
6 0110 1001 1010 0011
7 0111 1010 1001 0001
8 1000 1011 1000 1001
9 1001 1100 1111 1000
BCD: 0101 0001 0011 0111
Excess - 3: 1000 0100 0110 1010
2421: 1011 0001 0011 1101
6311: 0111 0010 0100 1010
Boolean Algebra
Boolean Algebra
• Boolean algebra is a mathematical system for the manipulation of
variables that can have one of two values.
• In formal logic, these values are “true” and “false.”
• In digital systems, these values are “on” and “off,” 1 and 0, or “high” and
“low.”
• Boolean expressions are created by performing operations on
Boolean variables.
• Common Boolean operators include AND, OR, and NOT.
14