Understanding the BCD converter — concept and principle
Binary-coded decimal (BCD) stores each decimal digit separately in four bits instead of converting the whole number to binary. It wastes some space, but the digits can be displayed or printed without any division, and decimal amounts are represented exactly. BCD is found in seven-segment display drivers, many real-time clock chips, some financial and legacy mainframe formats, and digital logic courses. This converter shows the standard 8421 BCD and the Excess-3 code for a decimal number.
How it is calculated
- BCD (8421): write each decimal digit as a 4-bit binary number with weights 8, 4, 2, 1. Digit d becomes d in binary, padded to four bits.
- Excess-3: add 3 to each digit first, then write the result in four bits, so 0 becomes 0011 and 9 becomes 1100.
- The calculator uses the integer part of the absolute value; a sign or fraction is not encoded.
The principle
Four bits can hold 16 patterns but a decimal digit needs only 10, so BCD uses 0000–1001 and leaves 1010–1111 unused. Because each nibble is one digit, a byte holding two digits (packed BCD) reads the same in hexadecimal as in decimal, which is why a clock register showing 0x59 means 59 seconds. Excess-3 is self-complementing: inverting every bit of a digit gives the code of 9 minus that digit, which simplified subtraction in early decimal machines. When BCD digits are added, a sum above 9 must be corrected by adding 6 to skip the six unused patterns.
Worked example
- Input: 2026, digits 2, 0, 2, 6.
- BCD: 2 = 0010, 0 = 0000, 2 = 0010, 6 = 0110, giving 0010 0000 0010 0110.
- Excess-3: add 3 to each digit: 5, 3, 5, 9.
- In four bits: 0101, 0011, 0101, 1001, giving 0101 0011 0101 1001.
- Check the complement rule on the last digit: inverting 1001 (6 + 3) gives 0110, which is 3 + 3, the Excess-3 code of 9 − 6 = 3.
How to read the result
Read the output four bits at a time from left to right; each group is one decimal digit. Packed into bytes, 2026 becomes 0x20 0x26. Plain binary of 2026 is 11111101010, only 11 bits, versus 16 bits in BCD. In general BCD spends 4 bits per digit where binary needs about 3.32 (log₂ 10), roughly 20% more storage for easy decimal handling.
Common mistakes
- Converting the whole number to binary and calling it BCD.
- Accepting nibbles 1010–1111 as valid digits in 8421 BCD.
- Adding BCD values with ordinary binary addition and forgetting the +6 correction.
Frequently asked questions
Why do clock chips use BCD?
The time can be sent straight to a display digit by digit, without converting from binary.
Is BCD the same as hexadecimal?
No, but a byte of packed BCD looks like the decimal number when written in hex, because only the digits 0–9 appear in each nibble.
What is the Excess-3 code of 0?
0011, because 0 + 3 = 3.
Sources: M. Morris Mano and Michael D. Ciletti, Digital Design, Pearson (binary codes: BCD, Excess-3)