Convert decimal to BCD (8421 binary coded decimal), decode BCD in binary or hex back to decimal, or convert an ordinary binary number to BCD.
BCD Formula
BCD, or binary-coded decimal, stores each decimal digit as its own 4-bit binary group. This calculator packs each digit of a number (up to 32 digits) into its own nibble; for a four-digit number, D1, D2, D3, and D4 are stored as four nibbles.
Encode four digits to packed BCD:
Equivalent binary grouping:
Decode packed BCD back to digits:
- BCD is the packed 16-bit binary-coded decimal value.
- D1 is the thousands digit.
- D2 is the hundreds digit.
- D3 is the tens digit.
- D4 is the ones digit.
- bin4(D) means the 4-bit binary form of one decimal digit.
- mod gives the remainder after division.
Choose Decimal to BCD and enter a whole number of up to 32 digits. Each digit must be from 0 to 9; any leading zeros you type are kept. The calculator converts each digit into a 4-bit BCD nibble, joins the nibbles in order, and also shows the equivalent hexadecimal packed value.
Choose BCD (binary) to decimal or BCD (hex) to decimal, then enter the value in that format. The calculator splits the value into 4-bit nibbles and reads each nibble as one decimal digit. Any nibble greater than 9 is invalid BCD.
Decimal Digits and 4-Bit BCD Codes
| Decimal digit | 4-bit BCD | Hex nibble |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
Common Packed BCD Examples
| Decimal digits | Packed BCD binary | Packed BCD hex |
|---|---|---|
| 0000 | 0000 0000 0000 0000 | 0x0000 |
| 1234 | 0001 0010 0011 0100 | 0x1234 |
| 5078 | 0101 0000 0111 1000 | 0x5078 |
| 9999 | 1001 1001 1001 1001 | 0x9999 |
Example Problems
Example 1: Encode 1011 into packed BCD
Enter 1011 in Decimal to BCD. This gives D1 = 1, D2 = 0, D3 = 1, and D4 = 1.
- D1 = 1 becomes 0001
- D2 = 0 becomes 0000
- D3 = 1 becomes 0001
- D4 = 1 becomes 0001
The packed BCD result is 0001 0000 0001 0001, which is 0x1011.
Example 2: Decode 0x2468 from packed BCD
Split the hexadecimal value into nibbles:
- 2 becomes digit 2
- 4 becomes digit 4
- 6 becomes digit 6
- 8 becomes digit 8
The decoded decimal digits are 2468. In binary, the packed BCD value is 0010 0100 0110 1000.
FAQ
What is BCD?
BCD means binary-coded decimal. Instead of converting the whole decimal number into normal binary, BCD converts each decimal digit separately. For example, the decimal digits 1234 become 0001 0010 0011 0100 in packed BCD.
Why is 0x1011 decoded as 1011 and not as decimal 4113?
In packed BCD, each hexadecimal digit represents one decimal digit. So 0x1011 is read as the nibbles 1, 0, 1, and 1. That gives the decimal digits 1011. If you treated 0x1011 as an ordinary hexadecimal number, its decimal value would be 4113, but that is not the BCD interpretation.
Why are A through F invalid in BCD?
Each BCD nibble must represent a decimal digit from 0 to 9. Hexadecimal values A, B, C, D, E, and F represent 10 through 15, which are not single decimal digits. A packed BCD value such as 0x12A4 is invalid because the A nibble is greater than 9.
