BCD to Binary Converter
Convert BCD (Binary-Coded Decimal) to pure binary and binary to BCD instantly. Supports validation, step-by-step breakdown, and bulk conversion.
About
Binary-Coded Decimal (BCD) represents each decimal digit (0 - 9) as a fixed 4-bit binary nibble. This encoding differs fundamentally from pure positional binary. A decimal value like 93 occupies 8 BCD bits (1001 0011) but only 7 bits in pure binary (1011101). BCD wastes roughly 20 - 25% of bit space because nibbles 1010 through 1111 are illegal. However, BCD avoids rounding errors in decimal arithmetic, which is why financial hardware (POS terminals, COBOL systems, certain FPGAs) still uses it. Feeding an illegal nibble into a BCD adder circuit produces undefined behavior. This tool validates every nibble before conversion.
The converter handles both directions: BCD β pure binary and pure binary β BCD. It flags invalid BCD nibbles, shows the intermediate decimal value, and provides a step-by-step breakdown of each nibble. This tool approximates no intermediate floating-point values. All arithmetic is integer-based. Note: for numbers exceeding 253 β 1 (JavaScriptβs safe integer limit), results may lose precision. Use BigInt-capable environments for cryptographic-scale BCD.
Formulas
BCD encoding maps each decimal digit d (0 β€ d β€ 9) independently to a 4-bit nibble. Given a decimal number N with digits dkdkβ1β¦d1d0, the BCD representation concatenates each digitβs 4-bit form:
where bin4(d) is the 4-bit binary representation of digit d, and β denotes concatenation.
To convert BCD back to pure binary, first recover the decimal value:
Then convert N to positional binary via successive division by 2:
A nibble is invalid BCD if its decimal value exceeds 9:
where di = individual decimal digit, k = number of digits β 1, N = reconstructed decimal integer, bin4 = zero-padded 4-bit binary function.
Reference Data
| Decimal Digit | BCD (4-bit) | Pure Binary | Hex | BCD Valid |
|---|---|---|---|---|
| 0 | 0000 | 0 | 0x0 | β |
| 1 | 0001 | 1 | 0x1 | β |
| 2 | 0010 | 10 | 0x2 | β |
| 3 | 0011 | 11 | 0x3 | β |
| 4 | 0100 | 100 | 0x4 | β |
| 5 | 0101 | 101 | 0x5 | β |
| 6 | 0110 | 110 | 0x6 | β |
| 7 | 0111 | 111 | 0x7 | β |
| 8 | 1000 | 1000 | 0x8 | β |
| 9 | 1001 | 1001 | 0x9 | β |
| - | 1010 | 1010 | 0xA | β Invalid |
| - | 1011 | 1011 | 0xB | β Invalid |
| - | 1100 | 1100 | 0xC | β Invalid |
| - | 1101 | 1101 | 0xD | β Invalid |
| - | 1110 | 1110 | 0xE | β Invalid |
| - | 1111 | 1111 | 0xF | β Invalid |
| Multi-digit BCD Examples | ||||
| 42 | 0100 0010 | 101010 | 0x2A | β |
| 99 | 1001 1001 | 1100011 | 0x63 | β |
| 100 | 0001 0000 0000 | 1100100 | 0x64 | β |
| 255 | 0010 0101 0101 | 11111111 | 0xFF | β |
| 1000 | 0001 0000 0000 0000 | 1111101000 | 0x3E8 | β |
| 9999 | 1001 1001 1001 1001 | 10011100001111 | 0x270F | β |