Convert EBCDIC hexadecimal to ASCII

How EBCDIC hex to ASCII conversion works, why the code page matters, which mainframe fields break when decoded as text, and how to check the result.

Converting EBCDIC hexadecimal to ASCII is a common way to make text from IBM mainframe and midrange systems readable on other platforms. It works when the bytes really are character data and you know which EBCDIC code page produced them. When either condition is uncertain, the output can look plausible and still be wrong. This review covers what the conversion changes, when it suits your purpose, and what to check before you rely on the result.

Is this conversion suitable for your use?

Recommendation: use EBCDIC-to-ASCII conversion for text fields such as names, descriptions, messages, log lines and source code, provided you can identify the source code page. The main benefit is that the output is ordinary text. It can be searched, edited, compared and read by any tool on an ASCII or Unicode system.

The decisive tradeoff is that the conversion is only as correct as the code page you choose. EBCDIC is a family of code pages, not one fixed table. Letters and digits match across the common variants, but several punctuation and national characters do not. A wrong choice usually fails quietly: most of the text looks right while brackets, currency signs or accented letters come out wrong.

Keep the data in its original EBCDIC form, or convert it with a record-aware tool, in these cases:

  • The data contains packed decimal (COMP-3), binary integers or floating-point fields. Byte-by-byte character conversion corrupts these values.
  • The data contains zoned decimal numbers with sign information in the last byte.
  • The data will be sent back to the mainframe and must match the original bytes exactly.
  • The data uses double-byte EBCDIC, such as mixed Japanese or Chinese text with shift-out and shift-in bytes, and your converter only handles single-byte code pages.
  • You need an exact byte record for forensic, audit or debugging purposes. In that case, keep the hex alongside the decoded text.

What the conversion actually changes

This conversion changes the stored characters. It is not a visual effect, and it is not related to mirrored text, styled Unicode fonts or CSS presentation. The process has three steps:

  • Parse the hex string into raw bytes. For example, C8 becomes the single byte 0xC8.
  • Look up each byte in an EBCDIC code page table to find its character.
  • Write that character out as ASCII, or more realistically as UTF-8.

Taken together, these steps replace one byte sequence with a different byte sequence that represents the same characters in another encoding. If the mapping is correct, the meaning of the text is preserved. Only the numeric codes change.

Here is a worked example using code page 037, a widely used US and Canadian EBCDIC variant. The phrase "Hello, World" encoded in EBCDIC 037 and in ASCII:

EBCDIC 037 hex:  C8 85 93 93 96 6B 40 E6 96 99 93 84
ASCII hex:       48 65 6C 6C 6F 2C 20 57 6F 72 6C 64
Text:            H  e  l  l  o  ,     W  o  r  l  d

Each byte maps to exactly one character, and the order does not change. Nothing is reversed or reordered. The example also shows that EBCDIC letters are not in one contiguous block. Uppercase A to I occupy C1 to C9, J to R occupy D1 to D9, and S to Z occupy E2 to E9. Lowercase follows the same pattern from 81 upward. The space is 40, not 20 as in ASCII. Digits 0 to 9 are F0 to F9.

Why "ASCII" is often the wrong target

ASCII has only 128 characters. EBCDIC code pages include characters ASCII cannot represent, such as the cent sign, the logical-not sign and accented letters. A converter that targets strict ASCII must drop these characters, substitute them or raise an error. In practice, most people searching for "EBCDIC to ASCII" want readable text on a modern system, so targeting UTF-8 is usually the better choice. For the plain English letters, digits and basic punctuation in the example above, UTF-8 output is identical to ASCII.

Code pages that differ

The table below shows a few well-known differences. It is not a complete list. Check the code page documentation for your system before converting data that contains punctuation or non-English characters.

Code page | Typical use | Notable difference
037 | US and Canada | Square brackets at BA and BB
1047 | z/OS UNIX and C code | Square brackets at AD and BD; also differs from 037 on caret and logical-not
500 | International | Brackets and exclamation mark in different positions from 037
1140 and similar | Euro-enabled updates of older pages | Euro sign replaces the generic currency sign at one position

Line endings are another source of disagreement. EBCDIC has both a newline control character (15) and a line feed (25), and converters do not all map them the same way. Many mainframe datasets also contain no line-ending characters at all. They use fixed-length records, or variable-length records with length prefixes, so record boundaries have to come from the record format rather than from the bytes.

The zoned decimal trap

Zoned decimal numbers store one digit per byte, using the same F0 to F9 range as text digits. That is why they often convert cleanly. The exception is the last byte, which can carry the sign in its upper half. For example, positive 1 may be stored as C1, which is the code for the letter A. A character converter will turn the number 123 into "12C", and negative values will end in letters from J onward or a brace. This is correct character conversion applied to non-character data. You can only avoid it by knowing the record layout, which on mainframes usually comes from a COBOL copybook.

Doing the conversion

Two common command-line approaches are shown below. Python's standard library includes several EBCDIC codecs, including cp037, cp273, cp500 and cp1140. It does not include 1047, so you would need a third-party codec or a different tool for that code page. The GNU iconv implementation supports a wider range of IBM code pages, including IBM1047.

python3 -c "print(bytes.fromhex('C8 85 93 93 96 6B 40 E6 96 99 93 84').decode('cp037'))"

echo 'C88593939640E6969993844B' | xxd -r -p | iconv -f IBM037 -t UTF-8

The first command should print "Hello, World". The second should print "Hello World." with a trailing period (4B in code page 037). These expected outputs are derived from the code page 037 table, not from a run recorded for this article. Run them yourself to confirm the behavior on your system. The dd utility also has a built-in EBCDIC-to-ASCII option, but it uses one fixed table that may not match your code page, so iconv or a named codec is the safer choice.

Online converters exist, but no specific tool was evaluated for this article. Their code page support, handling of invalid bytes and data handling practices are not covered here. Avoid pasting production data, personal data or credentials into a web tool unless you have checked its documented handling policy.

Will the result stay readable after copying or sharing?

For correctly converted text, generally yes. Unlike styled Unicode "fonts" or mirrored characters, the output uses ordinary characters. It does not depend on special glyphs or rendering tricks, so screen readers, search, sorting and editing tools treat it like any other text. Reading order is unchanged because the conversion maps bytes one-to-one and in sequence. This expectation follows from how the conversion works. No specific screen reader, editor or destination was tested for this article.

Problems usually come from the input rather than the conversion:

  • Control bytes in the source become control characters in the output. They may be invisible, may be stripped when pasted into some applications, or may break formatting.
  • If records had no line endings, the output is one long line until you split it at the record length.
  • Characters outside ASCII survive only if the target encoding and the receiving application both support them. Sharing UTF-8 output with a system that expects a legacy code page can produce mojibake.
  • Text decoded with the wrong code page often looks almost right, so reviewers may not notice the errors.

Checking that the meaning was preserved

  • Find out the source code page from the system owner, the dataset or file attributes, or the CCSID setting. Do not guess from the output alone.
  • Test with a sample that contains brackets, currency signs, accented letters and other characters that vary between code pages, and compare against a known-good rendering.
  • Convert back to EBCDIC with the same code page and compare against the original bytes. A clean round trip means no characters were lost or substituted.
  • Split out non-text fields using the record layout before converting, and decode them separately as numbers.
  • Keep the original hex until the converted output has been checked.

Gaps in this review

This article relies on the published structure of the EBCDIC code pages it names. It does not include measured results from specific converters, editors, screen readers or sharing platforms, and it does not cover every EBCDIC variant. If you need to rely on a particular destination or tool, test it with representative data from your own system.