Binary Codes
21
2.1.3 Higher-Density BCD Encoding
In the regular BCD encoding of decimal numbers, the number of bits needed to represent a given
decimal number is always greater than the number of bits required for straight binary encoding of the
same. For example, a three-digit decimal number requires 12 bits for representation in conventional
BCD format. However, since 2
10 > 10
3 , if these three decimal digits are encoded together, only 10
bits would be needed to do that. Two such encoding schemes are Chen-Ho encoding and the densely
packed decimal. The latter has the advantage that subsets of the encoding encode two digits in the
optimal seven bits and one digit in four bits like regular BCD.
2.1.4 Packed and Unpacked BCD Numbers
In the case of unpacked BCD numbers, each four-bit BCD group corresponding to a decimal digit is
stored in a separate register inside the machine. In such a case, if the registers are eight bits or wider,
the register space is wasted.
In the case of packed BCD numbers, two BCD digits are stored in a single eight-bit register. The
process of combining two BCD digits so that they are stored in one eight-bit register involves shifting
the number in the upper register to the left 4 times and then adding the numbers in the upper and lower
registers. The process is illustrated by showing the storage of decimal digits ‘5’ and ‘7’:
• Decimal digit 5 is initially stored in the eight-bit register as: 0000 0101.
• Decimal digit 7 is initially stored in the eight-bit register as: 0000 0111.
• After shifting to the left 4 times, the digit 5 register reads: 0101 0000.
• The addition of the contents of the digit 5 and digit 7 registers now reads: 0101 0111.
Example 2.1
How many bits would be required to encode decimal numbers 0 to 9999 in straight binary and BCD
codes? What would be the BCD equivalent of decimal 27 in 16-bit representation?
Solution
• Total number of decimals to be represented = 10 000 = 10
4
= 2
1329 .
• Therefore, the number of bits required for straight binary encoding = 14.
• The number of bits required for BCD encoding = 16.
• The BCD equivalent of 27 in 16-bit representation = 0000000000100111.
2.2 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 2.2 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
Précédent

- 43/741

Suivant