Binary Coded Decimal (BCD)
Why Do We Need BCD?
Computers and digital circuits operate using only two states: 0 and 1. This is the binary number system. Humans, however, naturally use the decimal number system, which has ten digits from 0 to 9. While computers can convert any decimal number into a single long binary string for calculations, this conversion is not always perfect for simple display or for handling numbers that must be exact in decimal (like money: $10.10). BCD solves this by providing a direct, digit-by-digit translation that is easy for both machines to store and for programmers to interpret as a decimal number.
Understanding the 8421 Code
The most common type of BCD is called 8421 BCD or Natural BCD. The numbers 8, 4, 2, and 1 are the weights of the four binary positions, from left to right. To find the decimal value of a 4-bit BCD code, you multiply each bit by its weight and add the results. This system directly uses the first ten binary combinations.
| Decimal Digit | BCD (4-bit Binary) | Calculation (8-4-2-1) |
|---|---|---|
| 0 | 0000 | (0x8)+(0x4)+(0x2)+(0x1)=0 |
| 1 | 0001 | (0x8)+(0x4)+(0x2)+(1x1)=1 |
| 2 | 0010 | (0x8)+(0x4)+(1x2)+(0x1)=2 |
| 3 | 0011 | (0x8)+(0x4)+(1x2)+(1x1)=3 |
| 4 | 0100 | (0x8)+(1x4)+(0x2)+(0x1)=4 |
| 5 | 0101 | (0x8)+(1x4)+(0x2)+(1x1)=5 |
| 6 | 0110 | (0x8)+(1x4)+(1x2)+(0x1)=6 |
| 7 | 0111 | (0x8)+(1x4)+(1x2)+(1x1)=7 |
| 8 | 1000 | (1x8)+(0x4)+(0x2)+(0x1)=8 |
| 9 | 1001 | (1x8)+(0x4)+(0x2)+(1x1)=9 |
Important: The binary codes for 1010 (10), 1011 (11), 1100 (12), 1101 (13), 1110 (14), and 1111 (15) are not valid in standard 8421 BCD. They are called illegal codes because a single decimal digit can never be greater than 9.
BCD vs. Pure Binary: A Clear Example
This is a crucial distinction. Let's convert the decimal number 137 into both pure binary and BCD.
Pure Binary: We convert the entire number to base-2.
$137_{10} = 128 + 8 + 1 = 1 \times 2^7 + 0 \times 2^6 + 0 \times 2^5 + 0 \times 2^4 + 1 \times 2^3 + 0 \times 2^2 + 0 \times 2^1 + 1 \times 2^0$
So, $137_{10} = 10001001_2$ (8 bits total).
BCD: We convert each digit separately.
1 -> 0001
3 -> 0011
7 -> 0111
So, $137_{10} = 0001\ 0011\ 0111_{BCD}$ (12 bits total).
Notice that BCD used more bits (12 vs. 8)! BCD is less efficient in terms of storage but much simpler to translate back to decimal for display. You can simply take each group of 4 bits and look it up in the table above.
How to Add Numbers in BCD
Adding two BCD numbers isn't as straightforward as normal binary addition because we must ensure the result for each digit group remains a valid BCD code (0000 to 1001). If the sum of two digits is greater than 9, or if a carry is generated, we need to add a correction factor of 6 (0110 in binary) to that digit group.
Why 6? In binary, adding 6 skips over the six illegal codes (1010 to 1111) and forces a carry to the next higher decimal digit, which is exactly what we need in decimal (where 9+1=10).
1. Write each number in BCD:
$47 = 0100\ 0111_{BCD}$
$35 = 0011\ 0101_{BCD}$
2. Add the lower (units) digit group: $0111 + 0101 = 1100$ (binary 12). This is an illegal BCD code (>9).
3. Add correction factor 6: $1100 + 0110 = 1\ 0010$. The 0010 (2) is the units digit of the result. The 1 is a carry to the next (tens) digit group.
4. Add the higher (tens) digit group PLUS the carry: $0100 + 0011 + 0001 = 1000$ (binary 8). This is a valid BCD code (≤9). No correction needed.
5. Combine the results: Tens = 1000 (8), Units = 0010 (2).
Final BCD Result: $1000\ 0010_{BCD}$, which is 82. Check: 47+35=82.
BCD in Action: Where You See It Every Day
BCD is everywhere in simple digital devices. Think about a classic digital alarm clock. The time is stored in registers as BCD values. When the circuit needs to advance the minutes from 59 to 00, it uses BCD addition logic. The BCD codes are then sent directly to the display driver chip, which lights up the correct segments for each digit. Using pure binary would require a more complex binary-to-decimal converter just to show the time on the screen.
Other common applications include:
- Electronic Calculators: They handle each keystroke as a decimal digit, making BCD the natural choice for internal storage and operations.
- Digital Multimeters and Weighing Scales: The numeric readout is driven directly from BCD values measured by the device.
- Financial Systems and Monetary Calculations: To avoid rounding errors that can occur when converting decimal fractions (like $0.10) to binary, systems often use BCD or related formats to guarantee exact decimal results.
Important Questions
The main advantage is its simplicity and accuracy in decimal representation. Converting between BCD and human-readable decimal is trivial—you just replace each group of 4 bits with its corresponding digit. This eliminates conversion errors and is perfect for devices that primarily take decimal input and produce decimal output, like calculators and digital displays.
The main disadvantage is lower storage efficiency and more complex arithmetic. BCD uses more bits to represent the same number compared to pure binary (e.g., 137 needed 12 bits in BCD vs. 8 in binary). Also, the hardware or software must include logic to handle the "+6" correction after BCD addition, making calculations slightly slower.
Yes. While 8421 is the most common, other weighted codes exist, like 2421 and 5421. There are also non-weighted codes like Excess-3 (XS-3), where the BCD code for a digit is its 8421 code plus 3 (0011). For example, decimal 0 is represented as 0011 in Excess-3. These variants have specific uses, such as simplifying subtraction circuits.
Footnote
[1] Nibble: A group of four bits. Half of a standard 8-bit byte. It is the fundamental unit of data in BCD.
[2] Binary: A base-2 number system using only two symbols, typically 0 and 1.
[3] Decimal: A base-10 number system using ten symbols, from 0 to 9.
[4] BCD: Binary Coded Decimal.
[5] Illegal Code: In standard 8421 BCD, any 4-bit pattern from 1010 (10) to 1111 (15), as they do not represent a single decimal digit.
