Page 1
Chapter 1 44
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
§ There are over 8,000 ways that you can chose 10 elements
from the 16 binary numbers of 4 bits. A few are useful:
Page 2
Chapter 1 44
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
§ There are over 8,000 ways that you can chose 10 elements
from the 16 binary numbers of 4 bits. A few are useful:
Chapter 1 45
§ What special property does the Gray code have
in relation to adjacent decimal digits?
GRAY CODE – Decimal
Decimal 8,4,2,1 Gray
0 0000 0000
1 0001 0100
2 0010 0101
3 0011 0111
4 0100 0110
5 0101 0010
6 0110 0011
7 0111 0001
8 1000 1001
9 1001 1000
Page 3
Chapter 1 44
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
§ There are over 8,000 ways that you can chose 10 elements
from the 16 binary numbers of 4 bits. A few are useful:
Chapter 1 45
§ What special property does the Gray code have
in relation to adjacent decimal digits?
GRAY CODE – Decimal
Decimal 8,4,2,1 Gray
0 0000 0000
1 0001 0100
2 0010 0101
3 0011 0111
4 0100 0110
5 0101 0010
6 0110 0011
7 0111 0001
8 1000 1001
9 1001 1000
Chapter 1 46
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.
§ Example: 1001 (9) = 1000 (8) + 0001 (1)
§ How many “invalid” code words are there?
§ What are the “invalid” code words?
Page 4
Chapter 1 44
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
§ There are over 8,000 ways that you can chose 10 elements
from the 16 binary numbers of 4 bits. A few are useful:
Chapter 1 45
§ What special property does the Gray code have
in relation to adjacent decimal digits?
GRAY CODE – Decimal
Decimal 8,4,2,1 Gray
0 0000 0000
1 0001 0100
2 0010 0101
3 0011 0111
4 0100 0110
5 0101 0010
6 0110 0011
7 0111 0001
8 1000 1001
9 1001 1000
Chapter 1 46
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.
§ Example: 1001 (9) = 1000 (8) + 0001 (1)
§ How many “invalid” code words are there?
§ What are the “invalid” code words?
Chapter 1 47
Warning: 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.
§ 13
10
= 1101
2
(This is conversion)
§ 13 Û 0001|0011 (This is coding)
Page 5
Chapter 1 44
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
§ There are over 8,000 ways that you can chose 10 elements
from the 16 binary numbers of 4 bits. A few are useful:
Chapter 1 45
§ What special property does the Gray code have
in relation to adjacent decimal digits?
GRAY CODE – Decimal
Decimal 8,4,2,1 Gray
0 0000 0000
1 0001 0100
2 0010 0101
3 0011 0111
4 0100 0110
5 0101 0010
6 0110 0011
7 0111 0001
8 1000 1001
9 1001 1000
Chapter 1 46
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.
§ Example: 1001 (9) = 1000 (8) + 0001 (1)
§ How many “invalid” code words are there?
§ What are the “invalid” code words?
Chapter 1 47
Warning: 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.
§ 13
10
= 1101
2
(This is conversion)
§ 13 Û 0001|0011 (This is coding)
Chapter 1 48
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, subtract 10 by adding 6 modulo 16.
8 1000 Eight
+5 +0101 Plus 5
13 1101 is 13 (> 9)
+0110 so add 6
carry = 1 0011 leaving 3 + cy
0001 | 0011 Final answer (two digits)
§ If the digit sum is > 9, add one to the next significant digit
Read More