Home Tools Blog About

Convert Decimal to BCD

In short

online decimal to BCD encoder with nibble, packed, unpacked and COMP-3 (signed) output modes. Client-side, instant, secure.

  • Runs in your browser
  • Nothing uploaded
  • Free, no sign-up

Encode a decimal integer as Binary-Coded Decimal - each digit becomes 4 bits. Four output formats: 4-bit nibbles, packed BCD bytes, unpacked BCD bytes, or COMP-3 (signed packed decimal used in COBOL). BigInt under the hood for arbitrary-precision input.

🛡
100% PrivateNo server uploads, ever
InstantRuns in your browser
💧
No WatermarksClean output, always
🆓
Free ForeverNo accounts, no limits

How to Use Convert Decimal to BCD

  1. Enter one decimal per line. Non-negative integers work in all modes; negatives require COMP-3 mode.
  2. Pick an output format:
    • Nibbles - plain 4-bit binary groups, best for teaching the idea: 57 → 0101 0111.
    • Packed BCD - two digits per byte as hex: 57 → 0x57. Common in embedded systems, RTC chips, and IBM mainframe files.
    • Unpacked BCD - one digit per byte, high nibble zero: 57 → 05 07. Used in some CPU instructions (e.g., x86 AAA/AAS).
    • COMP-3 - signed packed decimal per the IBM COBOL standard: digits packed two per byte, with the last nibble being C (positive), D (negative), or F (unsigned).
  3. Auto-pad prepends a zero nibble when the digit count is odd so packed and COMP-3 output always fits into whole bytes. Disable it to see what unaligned output would look like (with a warning).
  4. Enable the breakdown to see per-value details: digit count, byte count, and how many bits pure binary would have needed. Useful for comparing storage efficiency.
  5. Convert (or Ctrl+Enter). Live preview runs 150 ms after you stop typing. Invalid lines are flagged per-line, not the whole batch.
  6. Copy or download. Copy pushes to clipboard. Download saves as decimal-to-bcd-*.txt.

Frequently Asked Questions

What is BCD and why does it exist?

Binary-Coded Decimal stores each decimal digit as 4 bits (nibble). 57 → 0101 0111, not 111001 (which would be 57 in pure binary). BCD is less compact but avoids binary-to-decimal conversion at display time – ideal for 7-segment LED clocks, calculators, and financial systems where every displayed digit must match the stored value exactly.

What’s the difference between packed and unpacked BCD?

Packed stores two digits per byte – the high nibble is the first digit, the low nibble is the second: 57 = 0x57. Unpacked (also called “zoned”) uses one digit per byte with the high nibble zeroed or used for a zone code: 57 = 0x05 0x07. Packed is half the size but needs alignment; unpacked is easier to manipulate byte-by-byte.

What is COMP-3 and why does it include a sign nibble?

COMP-3 is IBM’s packed decimal format used in COBOL since the 1960s. Digits are packed two per byte, and the LAST nibble encodes the sign: C (hex 12) for positive, D (13) for negative, F (15) for unsigned. So -4204 2D. This way the sign travels with the number without needing a separate flag, which saves space in fixed-width mainframe record formats.

Why does “auto-pad” matter?

Packed BCD packs two digits per byte, so an odd-digit number like 123 doesn’t fit cleanly. Auto-pad prepends a zero nibble: 0 1 2 3 → 0x01 0x23. Without auto-pad the tool warns you – some hardware formats require a specific alignment convention and this toggle lets you see the raw un-aligned output to understand the problem.

How big can my input be?

No practical limit. The logic uses BigInt for precision, so a 100-digit decimal encodes correctly – each digit is independent in BCD. The standard parseInt would cap at 2^53 ≈ 16 decimal digits, which is why the naive version of this tool used to break silently at that boundary.

Why is BCD less space-efficient than binary?

Because 4 bits can encode 16 values (0-15), but BCD only uses 10 of them (0-9). The 6 “wasted” codepoints (1010-1111) are illegal in BCD. A 100-digit number takes 400 bits in BCD vs ~332 bits in pure binary – about 17% overhead. You trade that space for trivial digit-by-digit display.

Can I represent fractions in BCD?

Not directly – standard BCD is integer-only. Fixed-point BCD conventions exist (implicit decimal point at a known position), and “packed decimal” in COBOL PIC clauses encodes the scale separately. If you need fractions, store the scale as metadata and BCD-encode the scaled integer value.

Where is BCD used today?

Real-time clocks (RTCs – DS1307, PCF8563 chips store hours/minutes/seconds as BCD), financial systems where decimal-exactness is required (payment processing, accounting), embedded 7-segment display drivers, and legacy COBOL systems that haven’t migrated off COMP-3. Modern CPUs have largely deprecated BCD instructions (x86-64 dropped them entirely).

How does this differ from the “BCD to hex” tool?

This tool goes decimal → BCD: you give a number, it packs it. The BCD-to-hex sibling takes a hex string (like 0x4527) and interprets each nibble as a BCD digit. Round-trip: encode 4527 here in packed mode → get 0x45 0x27, then feed that to the BCD-to-hex decoder and you get back 4527.

Is the tool free, offline, and private?

Yes. All arithmetic happens in your browser via JavaScript and BigInt. No upload, no tracking, no account. Load the page once and the tool keeps working offline indefinitely.

Keep going

Related Tools

All Binary tools →