Circle D Converter
Convert between Decimal and BCD (Binary Coded Decimal) - The 8421 Code
What is BCD (Binary Coded Decimal)?
BCD (Binary Coded Decimal) is a method of encoding decimal numbers where each decimal digit is represented by its 4-bit binary equivalent. It's also known as the 8421 code because the bits represent values 8, 4, 2, and 1.
Example: Decimal 1234 = BCD: 0001 0010 0011 0100
BCD Encoding Table
| Decimal | BCD | Decimal | BCD |
|---|---|---|---|
| 0 | 0000 | 5 | 0101 |
| 1 | 0001 | 6 | 0110 |
| 2 | 0010 | 7 | 0111 |
| 3 | 0011 | 8 | 1000 |
| 4 | 0100 | 9 | 1001 |
Applications of BCD
- 📺 Seven-segment displays (digital clocks)
- 🧮 Calculators and digital counters
- 💻 Real-time clocks (RTCs)
- 🔢 Microprocessor applications
- 📊 Financial calculations (prevents floating-point errors)
BCD (Binary Coded Decimal), also known as Circle D or 8421 code, is a method of representing decimal numbers using binary. Each decimal digit (0-9) is represented by its 4-bit binary equivalent. For example, the decimal number 42 is represented as 0100 0010 in BCD. This representation makes it easier for digital circuits to display decimal numbers directly.
BCD is preferred in applications like digital clocks, calculators, and seven-segment displays because:
- It's easier to convert to decimal for display purposes
- Each digit is represented independently
- No rounding errors in decimal arithmetic
- Simpler hardware implementation for decimal display
- Easier for humans to read and debug
With n bits, BCD can represent 10^(n/4) decimal digits. For example:
- 4-bit BCD: 0 to 9 (1 digit)
- 8-bit BCD: 0 to 99 (2 digits)
- 12-bit BCD: 0 to 999 (3 digits)
- 16-bit BCD: 0 to 9999 (4 digits)
This converter supports up to 4-digit (16-bit) BCD numbers.
In pure binary, the entire number is converted as one binary value. In BCD, each decimal digit is converted separately to 4-bit binary. For example:
- Decimal 42 in binary: 101010 (6 bits)
- Decimal 42 in BCD: 0100 0010 (8 bits)
BCD uses more bits but is easier to convert to decimal for display.
In standard BCD, only binary values from 0000 to 1001 (0-9) are valid. Values from 1010 to 1111 (10-15) are invalid BCD codes. These are sometimes used for error detection or special purposes, but they don't represent valid decimal digits.
8421 refers to the weight of each bit in the 4-bit BCD representation:
- The leftmost bit (most significant) has weight 8
- The second bit has weight 4
- The third bit has weight 2
- The rightmost bit (least significant) has weight 1
For example, the BCD code 1001 represents: 1×8 + 0×4 + 0×2 + 1×1 = 9
To convert decimal to BCD:
- Separate the decimal number into individual digits
- Convert each digit to its 4-bit binary equivalent
- Combine the 4-bit groups in order
Example: Decimal 1234 → Digits: 1, 2, 3, 4 → BCD: 0001 0010 0011 0100
To convert BCD to decimal:
- Split the BCD code into 4-bit groups
- Convert each 4-bit group to its decimal equivalent (0-9)
- Combine the decimal digits in order
Example: BCD: 0001 0010 0011 0100 → Groups: 0001(1), 0010(2), 0011(3), 0100(4) → Decimal: 1234
Unpacked BCD: Each decimal digit is stored in a separate byte (8 bits), with the upper 4 bits unused (often set to 0).
Packed BCD: Two decimal digits are stored in each byte (4 bits per digit). This is more memory-efficient.
This converter uses packed BCD representation (4 bits per digit).
Yes! This converter supports BCD numbers of any length. Just enter the complete BCD code as a continuous string or space-separated groups. The converter will automatically detect the number of digits. Common lengths include:
- 8-bit BCD: 2 decimal digits (0-99)
- 16-bit BCD: 4 decimal digits (0-9999)
- 32-bit BCD: 8 decimal digits (0-99999999)