The BCD (Binary-Coded Decimal) Converter converts BCD (Binary to Coded Decimal) to and from decimal, validating input and preserving leading zeros.
Report an issue
Spotted a wrong result, broken field, or typo? Tell us below and we’ll fix it fast.
What Is a BCD (Binary-Coded Decimal) Converter?
A BCD converter turns between human-readable decimal digits and their binary-coded representations. In BCD, every decimal digit 0 through 9 maps to its 4-bit binary equivalent. Two digits can pack into one byte, or each digit can occupy a full byte in “unpacked” form.
This tool helps you encode a decimal string into BCD bytes or decode BCD bytes back to digits. It handles signs, padding, and decimal points using straightforward rules. That precision makes BCD popular in finance, retail scanners, smart meters, and legacy mainframe files.
Unlike pure binary, BCD keeps decimal digit boundaries intact. This prevents rounding surprises and eases display formatting. With the converter, you control nibble order, sign conventions, and separators, so you can match your target system exactly.

Equations Used by the BCD (Binary-Coded Decimal) Converter
BCD relies on simple weights for each nibble and positional weights for digits. These equations guide encoding, decoding, and arithmetic corrections when needed.
- Digit from nibble bits: d = 8·b3 + 4·b2 + 2·b1 + 1·b0 with the constraint 0 ≤ d ≤ 9. If d = 10–15, the nibble is invalid in pure BCD.
- Decimal value from digits: Value = Σ (d_i × 10^i), with i = 0 for the least significant digit. The sign applies after reconstruction.
- Packed BCD byte: byte = 16 × high_nibble + low_nibble. Each nibble is a digit (0–9) or a sign nibble in the last byte when signed packed BCD is used.
- Unpacked BCD: one byte per digit, with high nibble often 0000b and low nibble equal to the digit.
- Decimal point handling: Place the point after reconstructing digits using a fixed scale s. Final value = Value × 10^(−s).
- Decimal adjust (addition correction): After binary addition of BCD nibbles, if a nibble > 9 or a half-carry occurred, add 6 (0x06) to that nibble; if the high nibble then exceeds 9 or carry occurs, add 0x60.
The converter focuses on clean mapping between digits and nibbles. When decoding, it checks weights and flags any invalid nibble values. When encoding, it enforces digit limits and applies the chosen sign and scale options.
How the BCD (Binary-Coded Decimal) Method Works
BCD represents each decimal digit independently. This keeps decimal semantics while still using bits. Packed BCD stores two digits per byte. Unpacked BCD uses one byte per digit for simplicity at the cost of space.
- Encoding digits: Parse the decimal string into sign, digits, and an optional decimal point. Convert each digit 0–9 into its 4-bit nibble: 0000–1001.
- Packing bytes: For packed BCD, place the most significant digit in the high nibble and the next digit in the low nibble. If digits are odd, add a leading zero or place a sign nibble in the final low or high nibble per convention.
- Unpacked bytes: Write each digit to a full byte with high nibble 0000 and the low nibble equal to the digit. Append a sign byte if the format requires it.
- Signed formats: Many mainframe formats use C (1100) for positive, D (1101) for negative, and F (1111) for unsigned in the sign nibble, typically in the low nibble of the last byte.
- Scaling: A fixed number of fractional digits (scale) determines the decimal point location when decoding. Encoding stores digits only, not the point.
- Validation: Any nibble greater than 1001b (9) is invalid for pure data digits and triggers a warning, except when the position holds a sign nibble by design.
These rules create a reversible path: digits → nibbles → bytes and back again. The converter automates these steps and exposes layout options so your output matches your target system.
Inputs and Assumptions for BCD (Binary-Coded Decimal)
Set your inputs and options to match the BCD flavor you need. The converter accepts decimal strings or raw binary/hex for decoding and applies consistent assumptions for layout and sign.
- Mode: Encode decimal to BCD, or decode BCD to decimal.
- Format: Packed BCD (two digits per byte) or unpacked BCD (one digit per byte).
- Sign handling: None, trailing sign nibble (C/D/F), or separate sign byte.
- Scale (fractional digits): Integer count of digits after the decimal point.
- Endianness of digit packing: Most significant digit in the first nibble (standard) or alternate order if required by your system.
- Input parsing: Allow separators (spaces, underscore, commas), hex or binary for BCD bytes, and optional 0x prefix when decoding.
Ranges depend on available digits and your scale. Large numbers are supported as long as the total digit count fits memory and format rules. Odd digit counts may require zero padding or a sign nibble. Invalid nibble values 1010–1111 cause decode errors unless that nibble is the sign per your selected option.
How to Use the BCD (Binary-Coded Decimal) Converter (Steps)
Here’s a concise overview before we dive into the key points:
- Select Encode (decimal → BCD) or Decode (BCD → decimal).
- Choose Packed or Unpacked format under options.
- Set sign handling (None, C/D/F trailing nibble, or separate sign byte).
- Enter the scale (number of fractional digits) if your value has a decimal point.
- Provide the input: decimal number for Encode; hex or binary bytes for Decode.
- Pick any separators or grouping preferences for the output display.
These points provide quick orientation—use them alongside the full explanations in this page.
Case Studies
Retail price encoding: You need to store $2749.35 in packed BCD with two fractional digits and a positive sign nibble. Remove the point to get digits 274935. Pack: 27 → 0x27, 49 → 0x49, 35 with sign in low nibble → high nibble 3, low nibble C for positive → 0x3C. The byte sequence is 0x27 0x49 0x3C. What this means: Any system reading packed BCD with trailing C sign, scale 2, will decode 2749.35 correctly without binary rounding.
Embedded counter decoding: A sensor outputs three packed BCD bytes: 0x01 0x92 0xD3. Decode nibbles: 0,1,9,2,D,3. Treat the final nibble D as a negative sign; the preceding nibble 3 is the last digit. The digits are 01923 with sign negative, giving −192.3 if the scale is 1. What this means
Accuracy & Limitations
BCD preserves decimal digits exactly, but it comes with format constraints. The converter enforces nibble validity and helps you avoid subtle layout mismatches across systems.
- Only digits 0–9 are valid in data nibbles; 10–15 are invalid unless used as a sign nibble by convention.
- Scale is not stored in plain BCD; you must supply or agree on it out of band.
- Packed vs unpacked choices affect size and alignment; ensure the receiver expects the same.
- Signed formats vary: common sign codes are C, D, F, but some systems reverse nibble order or use different codes.
- Arithmetic on raw BCD requires correction steps; the converter focuses on representation, not full arithmetic.
Use the provided warnings to catch invalid nibbles, odd digit counts, or ambiguous settings. When exchanging data, document sign, scale, and packing so readers reconstruct values reliably.
Units Reference
BCD is unitless, but it depends on clear “representation units” like digit weight, nibble role, sign codes, and scale. Use this reference to align your inputs and outputs with a target file or device.
| Concept | Symbol/Code | Meaning | Example |
|---|---|---|---|
| Digit weight | 10^k | Each digit position k scales by a power of ten | 374 → 3×10^2 + 7×10^1 + 4×10^0 |
| Nibble bit weights | 8–4–2–1 | Bits map to a decimal digit, from MSb to LSb | 0101b → 5, 1001b → 9 |
| Packed byte | HH–LL | High nibble is first digit, low nibble is second digit | 0x27 → digits 2 and 7 |
| Sign nibble | C/D/F | C = positive, D = negative, F = unsigned/overpunch | 0x3C → digit 3 with positive sign |
| Scale (fractional digits) | s | Fixed count of digits after the decimal point | Digits 12345 with s=2 → 123.45 |
Match your data against the table. Confirm digit order, where the sign sits, and how many fractional digits to apply. When in doubt, test a small value and verify each nibble.
Troubleshooting
Run into an error or an unexpected value? Most issues come from a mismatch between packing, sign placement, or scale. Check these quick fixes and re-run the steps.
- Invalid nibble 1010–1111 appears: switch to a signed mode or mark that nibble as a sign.
- Wrong decimal point: adjust the scale; the point is not stored in plain BCD.
- Digits look reversed: confirm digit order and nibble endianness settings.
- Odd digit count: enable zero pad or place a trailing sign nibble per your format.
- Decode fails on byte text: ensure you entered hex as pairs or binary as groups of four.
If the data comes from a legacy system, consult its record layout. Look for terms like packed decimal, zoned decimal, overpunch, and the exact sign scheme used.
FAQ about BCD (Binary-Coded Decimal) Converter
What is the difference between packed and unpacked BCD?
Packed stores two digits per byte, saving space; unpacked stores one digit per byte with an extra high nibble, which simplifies parsing and display.
How do I represent negative values in BCD?
Use a sign nibble (commonly C for positive, D for negative, F for unsigned) in the last nibble, or a separate sign byte depending on your format.
Where is the decimal point stored in BCD?
It usually is not stored; you apply a fixed scale (number of fractional digits) when decoding or displaying the number.
Can I perform arithmetic directly on BCD?
Yes, but you must apply decimal adjust rules after add/subtract operations; the converter focuses on representation, not full arithmetic operations.
BCD (Binary-Coded Decimal) Terms & Definitions
BCD
A number encoding where each decimal digit is stored as a 4-bit binary value from 0000 to 1001.
Packed BCD
A BCD format that packs two digits into one byte, using one nibble per digit and often reserving the final nibble for the sign.
Unpacked BCD
A BCD format that stores one digit per byte, typically with the high nibble set to 0000 and the low nibble holding the digit.
Nibble
A group of four bits representing a single decimal digit in BCD or part of a packed byte.
Scale
The fixed count of fractional digits applied when interpreting or displaying BCD data.
Sign Nibble
A special nibble, often in the last byte, that indicates positive, negative, or unsigned status using codes like C, D, or F.
Zoned Decimal
An alternative decimal encoding where each digit occupies a byte with zone bits carrying sign or character information.
Decimal Adjust
An algorithmic correction after binary addition or subtraction to maintain valid BCD nibbles (e.g., add 0x06 or 0x60 as needed).
References
Here’s a concise overview before we dive into the key points:
- Binary-coded decimal – overview, formats, and examples
- Packed decimal (BCD) – representation and sign nibbles
- Intel DAA instruction – decimal adjust after addition
- IEEE 754-2019 – floating-point standard with decimal formats
- IBM z/OS – using packed decimal data
These points provide quick orientation—use them alongside the full explanations in this page.
References
- International Electrotechnical Commission (IEC)
- International Commission on Illumination (CIE)
- NIST Photometry
- ISO Standards — Light & Radiation