One of the limitations of binary is its inability to store certain fractions accurately. For example, it is not possible to store 0.1 in binary (it’s an irrational number when that radix is used). This leads to rounding errors when using floating-point arithmetic, which can cause significant problems, especially when the arithmetic is performed within a loop, compounding the issue.
Binary Coded Decimal (BCD) solves this problem, among others, by encoding each denary digit in its own nibble. Consider the binary integer encoding for 204:
This value is completely different in BCD, where the priority is not to encode data as efficiently as possible, but represent each denary digit as a separate unit:
Of course, this is inefficient; a nibble can store 16 values, and BCD only uses each one for a value between 0 and 9. But the separation of digits provides some advantages:
- No rounding errors: When digits are stored individually, they can be stored perfectly accurately, eliminating rounding errors.
- Simpler electronics can be used: Some devices are very simple, and it is not worth including the circuitry required for them to interact with binary integers. Using BCD allows these devices to be created with much simpler electronics[1].
Common applications of BCD, predictably, include devices that benefit from one or both of these advantages:
- Calculators: Using BCD avoids rounding errors. Also, the user inputs numeric values one digit at a time. Using BCD allows the calculator to support this input style without adding unnecessary complexity.
- Alarm clocks: While it is very possible to store the current time, and the user’s chosen alarm time, as binary integers, the circuitry involved is quite complex. It is much simpler to store the times in BCD and only sound the alarm when all four digits in the current time match the four digits in the alarm time.
- Simple embedded systems: Temperature alarms, air conditioners, microwaves, and more. These devices might not use BCD in reality (it depends on the choices made by the designers), but they are good candidates. For this reason, they might be featured in an exam question, so it’s worth bearing them in mind.
BCD has its disadvantages. The main issue is that it is a less efficient way of storing denary values, requiring roughly 20% more memory.
[1] This isn’t universally the case. General arithmetic using BCD requires 10-20% greater complexity when compared to using binary. Nonetheless, for simple devices, BCD is simpler.