Binary coded decimal (BCD) is a way to express each of the decimal digits with a binary code. There are only ten code groups in the BCD system, so it is very easy to convert between decimal and BCD. Because we like to read and write in decimal, the BCD code provides an excellent interface to binary systems. Examples of such interfaces are keypad inputs and digital readouts.

The 8421 BCD Code

The 8421 code is a type of BCD (binary coded decimal) code. Binary coded decimal means that each decimal digit, 0 through 9, is represented by a binary code of four bits. The designation 8421 indicates the binary weights of the four bits (23, 22, 21, 20). The ease of conversion between 8421 code numbers and the familiar decimal numbers is the main advantage of this code. All you have to remember are the ten binary combinations that represent the ten decimal digits as shown in Table 2–5. The 8421 code is the predominant BCD code, and when we refer to BCD, we always mean the 8421 code unless otherwise stated.


Invalid Codes

You should realize that, with four bits, sixteen numbers (0000 through 1111) can be represented but that, in the 8421 code, only ten of these are used. The six code combinations that are not used—1010, 1011, 1100, 1101, 1110, and 1111—are invalid in the 8421 BCD code.

To express any decimal number in BCD, simply replace each decimal digit with the appropriate 4-bit code, as shown by Example

EXAMPLE 1:

Convert each of the following decimal numbers to BCD:
(a) 35 

(b) 98 

(c) 170 

(d) 2469
Solution:


It is equally easy to determine a decimal number from a BCD number. Start at the right-most bit and break the code into groups of four bits. Then write the decimal digit represented by each 4-bit group.

EXAMPLE 2:

Convert each of the following BCD codes to decimal:

(a) 10000110 

(b) 001101010001 

(c) 1001010001110000

Solution:


BCD Addition

BCD is a numerical code and can be used in arithmetic operations. Addition is the most important operation because the other three operations (subtraction, multiplication, and division) can be accomplished by the use of addition. Here is how to add two BCD numbers:

Step 1: Add the two BCD numbers, using the rules for binary addition 

Step 2: If a 4-bit sum is equal to or less than 9, it is a valid BCD number.

Step 3: If a 4-bit sum is greater than 9, or if a carry out of the 4-bit group is generated, it is an invalid result. Add 6 (0110) to the 4-bit sum in order to skip the six invalid states and return the code to 8421. If a carry results when 6 is added, simply add the carry to the next 4-bit group.

EXAMPLE 3:

Add the following BCD numbers:

(a) 0011 + 0100 

(b) 00100011 + 00010101

(c) 10000110 + 00010011 

(d) 010001010000 + 010000010111

Solution:

The decimal number additions are shown for comparison.


Note that in each case the sum in any 4-bit column does not exceed 9, and the results are valid BCD numbers.

EXAMPLE 4:

Add the following BCD numbers:

(a) 1001 + 0100 

(b) 1001 + 1001

(c) 00010110 + 00010101 

(d) 01100111 + 01010011

Solution:

The decimal number additions are shown for comparison.