> bcd | decimal | binary <
// BCD - Binary-Coded Decimal for precise decimal arithmetic
>> features
Decimal Precision
Preserves decimal accuracy avoiding binary rounding errors.
Nibble Encoding
Each decimal digit encoded in exactly 4 bits (one nibble).
Multiple Formats
Support for 8421, 2421, 5421, Excess-3, and Gray BCD.
>> technical info
How BCD Works
BCD encodes each decimal digit (0-9) into 4 binary bits. Different BCD formats use different bit weightings: 8421 (standard), 2421 (self-complementing), 5421 (bi-quinary), Excess-3 (adds 3 to each digit), and Gray BCD (minimizes bit transitions). Packed BCD stores two digits per byte for efficiency.
BCD Formats Example
Decimal: 9 5 3
8421 BCD: 1001 0101 0011
2421 BCD: 1111 1011 0011
5421 BCD: 1100 1000 0011
Excess-3: 1100 1000 0110
Gray BCD: 1101 0111 0010
Packed: 10010101 00110000
(95) (30)
Why Use BCD
- Financial calculations requiring exact decimal representation
- Digital displays and seven-segment decoders
- Real-time clock circuits
- Calculator and computing chips
- PLC and industrial control systems
>> frequently asked questions
What is BCD?
Binary-Coded Decimal (BCD) is a binary encoding of decimal numbers where each decimal digit is represented by its 4-bit binary equivalent. It's used when decimal accuracy is crucial.
Why use BCD instead of binary?
BCD avoids rounding errors in decimal calculations and simplifies conversion to decimal displays. It's perfect for financial applications where exact decimal representation is required.
What is packed BCD?
Packed BCD stores two decimal digits in one byte (8 bits), with each nibble representing one digit. It's more space-efficient than unpacked BCD which uses a full byte per digit.
What are the different BCD formats?
Common BCD formats include: 8421 (standard weighted), 2421 (self-complementing), 5421 (bi-quinary), Excess-3 (each digit +3), and Gray BCD (minimizes bit changes between successive values).