Binary Coded Decimal to Hex Converter
Convert BCD (Binary Coded Decimal) to hexadecimal and hex to BCD instantly. Supports packed BCD, step-by-step breakdown, and conversion history.
About
Binary Coded Decimal (BCD) encodes each decimal digit 0 - 9 as a fixed-width 4-bit binary nibble. This encoding is standard in financial hardware, real-time clocks (RTCs), and BIOS date registers where decimal readability matters more than storage efficiency. A common error is treating raw BCD bit patterns as pure binary, which produces incorrect decimal values and corrupts downstream hex representations. This tool parses packed BCD input, validates that no nibble exceeds 10012 (910), reconstructs the decimal integer, and converts it to hexadecimal. It assumes standard 8421-weighted BCD. Excess-3 and Aiken codes are not supported.
Formulas
The 8421 BCD encoding maps each decimal digit to a 4-bit nibble weighted by powers of 2. Given a BCD bit string of n nibbles, the decimal reconstruction is:
where di is the decimal value of the i-th BCD nibble (counting from the least significant). Each nibble is decoded as:
A nibble is valid only if di ≤ 9. The final hexadecimal output is computed by converting the decimal integer D to base 16:
where D = decimal integer, H = hexadecimal string, b3…b0 = individual bits in a nibble (MSB to LSB), n = number of nibbles.
Reference Data
| Decimal Digit | BCD (8421) | Hex Equivalent | Excess-3 BCD | Aiken (2421) |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0011 | 0000 |
| 1 | 0001 | 1 | 0100 | 0001 |
| 2 | 0010 | 2 | 0101 | 0010 |
| 3 | 0011 | 3 | 0110 | 0011 |
| 4 | 0100 | 4 | 0111 | 0100 |
| 5 | 0101 | 5 | 1000 | 1011 |
| 6 | 0110 | 6 | 1001 | 1100 |
| 7 | 0111 | 7 | 1010 | 1101 |
| 8 | 1000 | 8 | 1011 | 1110 |
| 9 | 1001 | 9 | 1100 | 1111 |
| Nibbles 1010 - 1111 are invalid in 8421 BCD | ||||
| 10 | 0001 0000 | A | - | - |
| 15 | 0001 0101 | F | - | - |
| 16 | 0001 0110 | 10 | - | - |
| 99 | 1001 1001 | 63 | - | - |
| 100 | 0001 0000 0000 | 64 | - | - |
| 127 | 0001 0010 0111 | 7F | - | - |
| 255 | 0010 0101 0101 | FF | - | - |
| 256 | 0010 0101 0110 | 100 | - | - |
| 999 | 1001 1001 1001 | 3E7 | - | - |
| 1000 | 0001 0000 0000 0000 | 3E8 | - | - |
| 4096 | 0100 0000 1001 0110 | 1000 | - | - |
| 9999 | 1001 1001 1001 1001 | 270F | - | - |
| 65535 | 0110 0101 0101 0011 0101 | FFFF | - | - |