User Rating 0.0 β˜…β˜…β˜…β˜…β˜…
Total Usage 0 times
Enter groups of 4 binary digits (0 and 1 only). Spaces optional.
Examples:
Is this tool helpful?

Your feedback helps us improve.

β˜… β˜… β˜… β˜… β˜…

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.

bcd binary converter binary-coded-decimal number-systems digital-logic encoding

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:

BCD(N) = bin4(dk) β€– bin4(dkβˆ’1) β€– … β€– bin4(d0)

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:

N = kβˆ‘i=0 di β‹… 10i

Then convert N to positional binary via successive division by 2:

bin(N) = N mod 2 , N = ⌊N2βŒ‹ (repeat until N = 0)

A nibble is invalid BCD if its decimal value exceeds 9:

{
VALID if 00002 ≀ nibble ≀ 10012INVALID if 10102 ≀ nibble ≀ 11112

where di = individual decimal digit, k = number of digits βˆ’ 1, N = reconstructed decimal integer, bin4 = zero-padded 4-bit binary function.

Reference Data

Decimal DigitBCD (4-bit)Pure BinaryHexBCD Valid
0000000x0βœ“
1000110x1βœ“
20010100x2βœ“
30011110x3βœ“
401001000x4βœ“
501011010x5βœ“
601101100x6βœ“
701111110x7βœ“
8100010000x8βœ“
9100110010x9βœ“
- 101010100xAβœ— Invalid
- 101110110xBβœ— Invalid
- 110011000xCβœ— Invalid
- 110111010xDβœ— Invalid
- 111011100xEβœ— Invalid
- 111111110xFβœ— Invalid
Multi-digit BCD Examples
420100 00101010100x2Aβœ“
991001 100111000110x63βœ“
1000001 0000 000011001000x64βœ“
2550010 0101 0101111111110xFFβœ“
10000001 0000 0000 000011111010000x3E8βœ“
99991001 1001 1001 1001100111000011110x270Fβœ“

Frequently Asked Questions

BCD arithmetic circuits (e.g., the 74xx83 adder with correction logic) expect each nibble to map to a decimal digit 0 - 9. Nibbles above 1001 produce carry/correction signals at wrong times. In a BCD adder, when a nibble sum exceeds 9, the circuit adds 0110 (6) to correct back into valid BCD range. If your input already contains illegal nibbles, this correction produces garbage. The tool flags any nibble where the decimal equivalent exceeds 9.
BCD uses 4 bits per decimal digit. A k-digit decimal number requires 4k BCD bits. Pure binary needs only ⌈log2(10k)βŒ‰ β‰ˆ 3.32k bits. The overhead is roughly 20%. For a 3-digit number (max 999): BCD uses 12 bits, pure binary uses 10 bits. For 16 digits: BCD uses 64 bits, pure binary needs 54 bits.
This tool works with standard 8421 BCD (also called packed BCD), where each decimal digit occupies exactly 4 bits. Unpacked BCD (where each digit occupies 8 bits with the upper nibble zeroed) should first be stripped of its padding. Simply remove leading 0000 prefixes from each byte to get packed BCD before feeding into the converter.
The converter left-pads the input with zeros to make the total length a multiple of 4. For example, input 10010 (5 bits) becomes 00010010 (8 bits), yielding nibbles 0001 and 0010, which decode to decimal 12. This matches the convention used in hardware BCD registers.
Standard 8421 BCD has no native sign or radix point. Signed BCD typically uses a sign nibble (1100 for positive, 1101 for negative) appended at the end, as in IBM mainframe packed decimal format. Fractional BCD simply places a virtual decimal point between nibbles. This tool handles unsigned integer BCD only. For signed or fractional BCD, split the input manually at the sign/radix boundary.
Financial systems (COBOL, IBM System/360 descendants, POS terminals, tax calculators) require exact decimal arithmetic. Pure binary cannot represent 0.1 exactly (it becomes 0.0001100110011... repeating). BCD avoids this by encoding decimal digits directly. The 20% storage overhead is acceptable when rounding errors mean regulatory non-compliance. Modern x86 CPUs still include BCD instructions (DAA, DAS) for legacy compatibility.