User Rating 0.0
Total Usage 0 times
0 characters
Result

    
Quick Presets:
Is this tool helpful?

Your feedback helps us improve.

About

Binary-Coded Decimal (BCD) encodes each decimal digit of a number into a fixed 4-bit binary nibble. Unlike pure binary, BCD preserves decimal digit boundaries, which matters in financial systems, embedded controllers, and legacy mainframe protocols (IBM System/360 used packed BCD natively). Misinterpreting packed vs. unpacked format corrupts data silently - a 0xF padding nibble read as a digit produces garbage. This tool converts ASCII character codes into their BCD representations (both packed and unpacked) and reverses the process. It assumes standard printable ASCII range (0x20 - 0x7E). Note: BCD only represents decimal digits 0 - 9, so each ASCII code is first decomposed into its constituent decimal digits before encoding.

Packed BCD stores two digits per byte, halving storage compared to unpacked format, but requires careful handling of odd-length digit strings (this tool pads with 0xF as per IBM convention). Unpacked BCD zeros the upper nibble of each byte, wasting space but simplifying per-digit access. This tool approximates standard BCD encoding conventions and does not handle sign nibbles (0xC/0xD) used in COBOL signed fields.

ascii bcd binary-coded-decimal converter encoding packed-bcd unpacked-bcd hex

Formulas

BCD encoding decomposes each ASCII character's decimal code into individual digits, then maps each digit to a 4-bit nibble.

For a character with ASCII code c, extract the decimal digits:

digits = decimalDigits(c)

Unpacked BCD: each digit di maps to one byte:

bytei = 0000 di (binary), i.e., upper nibble = 0x0, lower nibble = di

Packed BCD: pair digits into bytes:

bytej = (d2j << 4) | d2j+1

If the total digit count is odd, the final nibble is padded with 0xF:

bytelast = (dn << 4) | 0xF

Where c = ASCII character code (decimal), di = the i-th decimal digit of c, 0xF = padding nibble (1111 binary) per IBM packed decimal convention, and << = bitwise left shift operator.

Reference Data

ASCII CharDecimal CodeHex CodeDecimal DigitsUnpacked BCD (Hex)Packed BCD (Hex)
0480x304, 804 0848
1490x314, 904 0949
9570x395, 705 0757
A650x416, 506 0565
B660x426, 606 0666
Z900x5A9, 009 0090
a970x619, 709 0797
z1220x7A1, 2, 201 02 0212 2F
Space320x203, 203 0232
!330x213, 303 0333
+430x2B4, 304 0343
.460x2E4, 604 0646
/470x2F4, 704 0747
@640x406, 406 0464
[910x5B9, 109 0191
~1260x7E1, 2, 601 02 0612 6F
{1230x7B1, 2, 301 02 0312 3F
}1250x7D1, 2, 501 02 0512 5F
%370x253, 703 0737
#350x233, 503 0535

Frequently Asked Questions

Unpacked BCD stores one decimal digit per byte - the upper nibble is always 0x0 and the lower nibble holds the digit value (0 - 9). This wastes 4 bits per digit but allows direct byte-level digit access. Packed BCD stores two digits per byte (first digit in upper nibble, second in lower nibble), halving storage. However, odd digit counts require a padding nibble, typically 0xF. IBM mainframes (COBOL, PL/I) use packed BCD extensively for decimal arithmetic.
BCD is a decimal encoding - it can only represent digits 0 - 9 in each nibble. ASCII character "A" has decimal code 65, which is not a single digit. The converter splits 65 into digits 6 and 5, then encodes each as a BCD nibble. This is the standard approach for encoding arbitrary numeric values in BCD format. Characters with codes above 99 (e.g., "z" = 122) produce three BCD digits.
When a packed BCD digit sequence has an odd number of digits, the last byte only has one meaningful digit in the upper nibble. The lower nibble is filled with 0xF (1111 binary) to indicate padding. This is the IBM convention. Some systems use 0x0 padding instead. This tool follows the 0xF convention. When decoding packed BCD back to ASCII, 0xF nibbles are stripped as padding.
Technically yes - any integer can be decomposed into decimal digits and BCD-encoded. However, this tool restricts input to printable ASCII (0x20 - 0x7E, codes 32 - 126) to avoid ambiguity with control characters. Control characters (codes 0 - 31) have no visual representation and their BCD encoding, while valid, is rarely useful outside specific protocol implementations.
This is a real challenge. ASCII code 65 produces BCD digits [6, 5], but so would two separate characters with codes 6 and 5 (if they existed in printable range). The reversal uses a delimiter-aware approach: each character's BCD digit group is separated by a space in the output. During BCD-to-ASCII conversion, you must provide the hex bytes with proper spacing per character group. The tool parses space-delimited byte groups to reconstruct each original character code.
No. EBCDIC is a different character encoding used on IBM mainframes with a completely different code page mapping. Signed packed BCD (used in COBOL COMP-3 fields) uses the final nibble as a sign indicator (0xC = positive, 0xD = negative, 0xF = unsigned). This tool treats 0xF strictly as padding, not as a sign. For signed BCD conversion, additional logic for sign nibble interpretation is required.