Binary-Coded Decimal (BCD) With Worked Examples
Binary-coded decimal stores each decimal digit in its own 4 bits. 8421 BCD vs plain binary, invalid codes, a real-time clock register and a converter.
Binary-coded decimal (BCD) stores a number one decimal digit at a time, with each digit in its own 4 bits. In the common 8421 form, 59 is 0101 1001: 0101 for the 5 and 1001 for the 9. Plain binary would store 59 as 111011.
How 8421 BCD works
The name lists the weights of the four bits in each digit: 8, 4, 2, 1. Each decimal digit 0–9 gets its usual 4-bit binary pattern, and the digits are simply placed side by side.
| Decimal digit | BCD | Decimal digit | BCD |
|---|---|---|---|
| 0 | 0000 | 5 | 0101 |
| 1 | 0001 | 6 | 0110 |
| 2 | 0010 | 7 | 0111 |
| 3 | 0011 | 8 | 1000 |
| 4 | 0100 | 9 | 1001 |
So 2026 in BCD is 0010 0000 0010 0110. Reading it back needs no arithmetic: split into groups of four and read each group as a digit.
BCD vs plain binary
| Decimal | BCD | Plain binary | Bits (BCD vs binary) |
|---|---|---|---|
| 9 | 1001 | 1001 | 4 vs 4 |
| 10 | 0001 0000 | 1010 | 8 vs 4 |
| 59 | 0101 1001 | 111011 | 8 vs 6 |
| 99 | 1001 1001 | 1100011 | 8 vs 7 |
| 255 | 0010 0101 0101 | 11111111 | 12 vs 8 |
| 2026 | 0010 0000 0010 0110 | 11111101010 | 16 vs 11 |
BCD uses more bits, because six of the sixteen 4-bit patterns are never used. In exchange, converting to and from human-readable digits is trivial.
Invalid codes: 1010 to 1111
The patterns 1010 through 1111 (10–15) are not valid 8421 BCD digits. A decoder must reject them, which is what the calculator on this page does: 1010 is “not a valid BCD digit”. When BCD addition produces one of these patterns, or carries out of a digit, hardware adds 6 (0110) to skip the unused codes. For example, 8 + 5 in BCD: 1000 + 0101 = 1101 (invalid), and 1101 + 0110 = 1 0011, which is BCD for 13.
Where BCD is used
Real-time clock chips. Texas Instruments’ bq32000 RTC keeps the time in BCD registers: its seconds register holds the tens of seconds in one field and the units in another. A seconds register reading 0x59 therefore means 59 seconds, not 89. Reading these registers as plain binary is a classic firmware bug.
Seven-segment displays. Each digit of a display needs its own value 0–9, and BCD hands it over directly, so display driver chips accept BCD input.
Financial and decimal arithmetic. Decimal fractions such as 0.1 have no exact binary representation, so systems that must round like a person would (money, tax) use decimal arithmetic. Some mainframe processors store this as packed decimal, two BCD digits per byte; in software, Python’s decimal module serves the same purpose.
Packed vs unpacked BCD
Packed BCD puts two digits in one byte (0x59 for 59). Unpacked BCD uses a whole byte per digit, with the digit in the low four bits (0x05 0x09). ASCII digits are close relatives of unpacked BCD: “5” is 0x35, and its low nibble is the digit itself.
For plain binary conversions, the step-by-step solver multiplies each bit by its power of 2. The decimal place-value chart explains the base-10 side of BCD.
Sources
- bq32000 Real-Time Clock (RTC) datasheet, Rev. F — Texas Instruments. seconds register stores tens and units of seconds in BCD
- decimal — Decimal fixed point and floating point arithmetic — Python documentation
How we made this
Computed and checked by tests. BCD encodings come from src/lib/calc/bcd.js (tested: 2026 → 0010 0000 0010 0110; 1001 0101 → 95; 1010 rejected). The real-time clock example is taken from the register description in TI's bq32000 datasheet, which we read for this article.
Performed by Claude, an AI assistant working in the BinConvert repository (Node.js 25 test runner), November 16, 2026.
This article was drafted with AI assistance. Every example, calculation and command output on this page was re-run or checked before release; every BCD and binary pattern was regenerated and compared. Review: automated test suite and source check, November 16, 2026.
Spotted an error? Tell us and we will correct it.