BCD to Hex Converter
Convert Binary-Coded Decimal (BCD) to hexadecimal and hex to BCD instantly. Supports packed BCD, validates nibbles, and shows step-by-step conversion.
About
Binary-Coded Decimal (BCD) encodes each decimal digit (0 - 9) into a fixed 4-bit binary nibble. A valid BCD nibble never exceeds 1001 (9 in decimal). Nibbles from 1010 through 1111 are illegal in BCD and indicate corrupted data or an encoding error. Misinterpreting BCD as straight binary produces incorrect values that cascade through financial systems, industrial PLCs, and legacy COBOL data stores. This tool validates every nibble before conversion and flags illegal codes immediately.
Packed BCD stores two decimal digits per byte, making it space-efficient for applications like mainframe transaction records and seven-segment display drivers. The conversion from packed BCD to hexadecimal requires first recovering the decimal value, then re-encoding in base-16. This tool handles arbitrarily long BCD strings. Note: leading zeros in the decimal intermediate are preserved to maintain digit alignment with the original BCD word length.
Formulas
Packed BCD encodes one decimal digit per 4-bit nibble. A BCD string of length n bits represents n รท 4 decimal digits. The decimal recovery formula:
where di is the decimal value of the i-th nibble (from least significant), and k is the total number of nibbles. Each di must satisfy 0 โค di โค 9.
Once the decimal value D is recovered, the hexadecimal conversion uses repeated division:
where hj โ {0 - 9, A - F} are the hex digits and m is the number of hex digits. The validity constraint per nibble is:
where D = recovered decimal value, di = decimal digit from nibble i, hj = hexadecimal digit at position j, k = total nibble count, m = hex digit count.
Reference Data
| Decimal Digit | BCD (4-bit) | Hex | Binary (True) | Valid BCD? |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0000 | Yes |
| 1 | 0001 | 1 | 0001 | Yes |
| 2 | 0010 | 2 | 0010 | Yes |
| 3 | 0011 | 3 | 0011 | Yes |
| 4 | 0100 | 4 | 0100 | Yes |
| 5 | 0101 | 5 | 0101 | Yes |
| 6 | 0110 | 6 | 0110 | Yes |
| 7 | 0111 | 7 | 0111 | Yes |
| 8 | 1000 | 8 | 1000 | Yes |
| 9 | 1001 | 9 | 1001 | Yes |
| - | 1010 | A | 1010 | No (illegal) |
| - | 1011 | B | 1011 | No (illegal) |
| - | 1100 | C | 1100 | No (illegal) |
| - | 1101 | D | 1101 | No (illegal) |
| - | 1110 | E | 1110 | No (illegal) |
| - | 1111 | F | 1111 | No (illegal) |
| 42 | 0100 0010 | 2A | 0010 1010 | Yes (packed) |
| 99 | 1001 1001 | 63 | 0110 0011 | Yes (packed) |
| 128 | 0001 0010 1000 | 80 | 1000 0000 | Yes (packed) |
| 255 | 0010 0101 0101 | FF | 1111 1111 | Yes (packed) |
| 1000 | 0001 0000 0000 0000 | 3E8 | 0011 1110 1000 | Yes (packed) |
| 9999 | 1001 1001 1001 1001 | 270F | 0010 0111 0000 1111 | Yes (packed) |