Binary Coded Decimal
The binary coded decimal (BCD) is a type of binary code used to represent a given decimal number in an equivalent binary form. BCD-to-decimal and decimal-to-BCD conversions are very easy and straightforward. It is also far less cumbersome an exercise to represent a given decimal number in an equivalent BCD code than to represent it in the equivalent straight binary form discussed in the previous chapter. The BCD equivalent of a decimal number is written by replacing each decimal digit in the integer and fractional parts with its four-bit binary equivalent. As an example, the BCD equivalent of (23.15)10 is written as (0010 0011.0001 0101)BCD. The BCD code described above is more precisely known as the 8421 BCD code, with 8, 4, 2 and 1 representing the weights of different bits in the four-bit groups, starting from MSB and proceeding towards LSB. This feature makes it a weighted code, which means that each bit in the four-bit group representing a given decimal digit has an assigned
Decimal        8421 BCD code      4221 BCD code          5421 BCD code
0                      0000                      0000                          0000
1                      0001                      0001                            0001
破茧歌词
张哲瀚是谁2                      0010                      0010                            0010
3                      0011                      0011                            0011
4                      0100                      1000                            0100虎牙猴三棍
5                      0101                      0111                            1000
6                      0110                      1100                            1001
7                      0111                      1101                            1010
8                      1000                      1110                            1011
9                      1001                      1111                            1100
weight. Other weighted BCD codes include the 4221 BCD and 5421 BCD codes. Again, 4, 2, 2 and 1 in the 4221 BCD code and 5, 4, 2 and 1 in the 5421 BCD code
represent weights of the relevant bits. Table 2.1 shows a comparison of 8421, 4221 and 5421 BCD codes. As an example, (98.16)10 will be written as 1111 1110.0001 1100 in 4221 BCD code and 1100 1011.0001 1001 in 5421 BCD code. Since the 8421 code is the most popular of all the BCD codes, it is simply referred to as the BCD code.
BCD-to-Binary Conversion
A given BCD number can be converted into an equivalent binary number by first writing its decimal equivalent and then converting it into its binary equivalent. we will find the binary equivalent of the BCD number 0010 1001.0111 0101:傅艺伟图片
• BCD number: 0010 1001.0111 0101.
• Corresponding decimal number: 29.75.
• The binary equivalent of 29.75 can be determined to be 11101 for the integer part and .11 for the fractional part.
• Therefore, (0010 1001.0111 0101)BCD =(11101.11)2.
Binary-to-BCD Conversion
The process of binary-to-BCD conversion is the same as the process of BCD-to-binary conversion executed in reverse order. A given binary number can be converted into an equivalent BCD number by first determining its decimal equivalent and then writing the corresponding BCD equivalent
Excess-3 Code
The excess-3 code is another important BCD code. It is particularly significant for arithmetic operations as it overcomes the shortcomings encountered while using the 8421 BCD code to add two decimal digits whose sum exceeds 9. The excess-3 code has no such limitation, and it considerably simplifies arithmetic operations. Table (1) lists the excess-3 code for the decimal numbers 0–9. The excess-3 code for a given decimal number is determined by adding ‘3’ to each decimal digit in the given
number and then replacing each digit of the newly found decimal number by its four-bit binary equivalent. It may be mentioned here that, if the addition of ‘3’ to a digit produces a carry, as is the case with the digits 7, 8 and 9, that carry should not be taken forward. The result of addition should be taken as a single entity and subsequently replaced with its excess-3 code equivalent. As an example, let us find the excess-3 code for the decimal number 597:
• The addition of ‘3’ to each digit yields the three new digits/numbers ‘8’, ‘12’ and ‘10’.
• The corresponding four-bit binary equivalents are 1000, 1100 and 1010 respectively.• The excess-3 code for 597 is therefore given by: 1000 1100 1010=100011001010.
Also, it is normal practice to represent a given decimal digit or number using the maximum number of digits that the digital system is capable of handling. For example, in four-digit decimal arithmetic, 5 and 37 would be written as 0005 and 0037 respectively. The corresponding 8421 BCD equivalents would be 0000000000000101 and 0000000000110111 and the excess-3 code equivalents would be 0011001100111000 and 0011001101101010. Corresponding to a given excess-3 code, the equivalent decimal number can be determined by first splitting the number into four-bit groups, starting from the radix point, and then subtracting 0011 from each four-bit group. The new number is the 8421 BCD equivalent of the given excess-3 code, which can subsequently be converted into the equivalent decimal number. As an example, following these steps, the decimal equivalent of excess-3 number 01010110.10001010 would be 23.57. Another significant feature that makes this code attractive for performing arithmetic operations is that the complement of the excess-3 code of a given decimal number yields the excess-3 code for 9’s complement of the decimal number. As adding 9’s complement of a decimal number
B to a decimal number A achieves A – B, the excess-3 code can be used effectively for both addition and subtraction of decimal numbers.
Table (1) lists the excess-3 code for the decimal numbers 0–9. Decimal number    Excess-3 code     
  Decimal number          Excess-3 code
星月神话 金莎0                              0011                        5                            1000
朱之文歌曲我要回家
1                              0100                        6                            1001
2                              0101                        7                            1010
3                              0110                        8                            1011
4                              0111                        9 1100
Example
Find (a) the excess-3 equivalent of (237.75)10 and (b) the decimal equivalent of the excess-3 number 110010100011.01110101.
Solution
(a) Integer part=237. The excess-3 code for (237)10 is obtained by replacing 2, 3 and
7 with the four-bit binary equivalents of 5, 6 and 10 respectively. This gives the excess-3 code for (237)10 as: 0101 0110 1010=010*********. Binary Codes 23 Fractional part=.75. The excess-3 code for (.75)10 is obtained by replacing 7 and 5 with the four-bit binary equivalents of 10 and 8 respectively. That is, the excess-3 code for (.75)10 =.10101000. Combining the results of the integral and fractional parts, the excess-3 code for (237.75)10 =010*********.10101000.
(b)The excess-3 code=110010100011.01110101=1100 1010 0011.0111 0101. Subtracting 0011 from each four-bit group, we obtain the new number as:
1001 0111 0000.0100 0010. Therefore, the decimal equivalent=(970.42)10.
Gray Code
The Gray code was designed by Frank Gray at Bell Labs and patented in 1953. It is an unweighted binary code in which two successive values differ only by 1 bit. Owing to this feature, the maximum error that can creep into a system using the binary Gray code to encode data is much less than the worst-case error encountered in the case of straight binary encoding. Table (3) lists the binary and Gray code equivalents of decimal numbers 0–15. An examination of the four-bit Gray code numbers, as listed in Table (3), shows that the last entry rolls over to the first entry. That is, the last and the first
entry also differ by only 1 bit. This is known as the cyclic property of the Gray code. Although there can be more than one Gray code for a given word length, the term was first applied to a specific binary code for non-negative integers and called the binary-reflected Gray code or simply the Gray code. There are various ways by which Gray codes with a given number of bits can be remembered. One such way is to remember that the least significant bit follows a repetitive pattern of ‘2’ (11, 00, 11, _ _ _ ), the next higher adjacent bit follows a pattern of ‘4’ (1111, 0000, 1111, _ _ _ ) and so on. We can also generate the n-bit Gray code recursively by prefixing a ‘0’ to the Gray code for n−1 bits to obtain the first 2n−1 numbers, and then prefixing ‘1’ to the reflected Gray code for n−1 bits to obtain the remaining 2n−1 numbers. The reflected Gray code is nothing but the code written in reverse order.