You must have seen the digital clock in the railway station or at many other places. The hour, minute and second digits are seven-segment displays that deal with binary coded decimal (BCD) numbers. In this particular article, we will learn about the BCD code.
BCD is a way to express each decimal digit in binary. Each decimal digit starting from 0 to 9 has its own BCD code, which is the 4-bit unsigned binary equivalent of the digit. And using these individual BCD codes, we can write the BCD value of any large decimal number. For example, decimal number 13 can be represented as “0001_0011” (‘_’ is given for ease of reading). In the above example, you can observe that we just replaced ‘1’ and ‘3’ with their 4-bit binary equivalents.
Rule: To convert a decimal number to its BCD, just replace each digit of the decimal number with its 4-bit binary equivalent. |
We need to understand that though BCD is a binary representation of decimal numbers, this is not the same as binary equivalent of a decimal number. To realize this, we will take the same example, which is the decimal number 13. The binary equivalent of 13 is “1101”, whereas the corresponding BCD is “00010011”. Even though the use of binary numbers is more efficient in a digital system, most human beings prefer to deal with decimal numbers. Thereby, the BCD code provides an excellent interface to binary systems, for example, keypad inputs and digital readouts.
Example: How many bits would be required to encode decimal numbers 0 to 99 in straight binary and BCD codes? Solution:
|
Packed and Unpacked BCD Numbers
The BCD code of a decimal digit is a group of four binary bits. In the case of unpacked BCD numbers, each group of 4 binary bits is stored in a register of a digital system. However, if the register size is 8-bit or more, then every storage of the BCD number wastes a lot of memory locations. In the case of an 8-bit register, the lower 4 bits store the BCD number, and the upper 4 bits store zeros. To save the memory locations, BCD numbers can be stored in packed form. In the case of a packed BCD number, an 8-bit register can hold two BCD digits, one in upper 4-bits and another in lower 4-bits. Most computer processors store BCD in packed form.
Here is the Assembly Language Program for Unpacking the Packed BCD number in 8085 Microprocessor.
8421 BCD code
The most popular BCD code is the 8421 code. The designation 8421 indicates the binary weights of four bits used in the BCD (23, 22, 21, 20). Though there are different types of BCD codes, due to the popularity of the 8421 code, in general, BCD refers to the 8421 code unless otherwise stated.
The following series of articles will cover different concepts of BCD codes.