banner image

EBCDIC, ASCII and Numbers Conversion

EBCDIC and ASCII are very common terms used when describing files, but when numeric fields are involved conversion is not straightforward. eMag has several solutions for the EBCDIC to ASCII conversion problem.

EBCDIC and ASCII are both ways of mapping computer codes to characters and numbers, as well as other symbols typically used in writing. Most current computers have a basic storage element of 8 bits, normally called a byte. This can have 256 possible values. 26 of these values need to be used for A-Z, and another 26 for a-z. 0-9 take up 10, and then there are many accented characters and punctuation marks, as well as control codes such as carriage return (CR) and line feed (LF). EBCDIC and ASCII both perform the same task, but they use different values for each symbol. For instance, in ASCII a 'E' is code 69, but in EBCDIC it is 197.

Text Conversion
Conversion from EBCDIC to ASCII is very easy. It can be performed by a look up table, and for the example above, all 197s would need converting to 69. Thus an EBCDIC or ASCII text file can be converted very easily.

Numeric Conversion
Numbers can be stored in many ways on a computer. Four examples are:

  • Text string
  • Binary
  • Packed decimal
  • Floating point

A text string is very simple and portable. It is written as numbers using standard symbols.

Binary numbers use the raw bytes in the computer to store numbers. Thus a single byte can be used to store any number from 0 to 255. If two bytes are used (16 bits) then numbers up to 65535 can be saved (i.e. 64K). 4 bytes can store up to 4G, (just over 4,000 million). The biggest problem with this type of number storage is how the bytes are ordered. With 4 bytes the order could be the least significant byte first or most significant. The first is called Little Endonian, and the second is Big Endonian. The first is also referred to as Intel, and the second as Motorola ordering. Which is best? The answer is similar to what one would reply in response to the question of which side of the road is best to drive on. In USA they drive on the right side, and in Britain the left side. (In Italy it is both sides!!).

Using Intel ordering, the number 260 would be 04H 01H, fort Motorola it would be 01H 04H.

Packed decimal numbers, COMP-3, is another way of storing numbers. In text mode each digit takes a single byte. In packed decimal, each digit takes just 4 bits (a nibble). These nibbles are then packed together, and the final nibble represents the sign. These are C (credit) is a +, D (debit) is a - and F is unsigned, i.e. +. The number 260 in packed decimal would be: 26H 0FH or 26H 0CH

The problem with ASCII/EBCDIC conversion when dealing with records that contain both text and numbers is that numbers must not be converted with the same byte conversion that is used for ASCII/EBCDIC conversion. The only truly portable way to convert such records is on a per field basis. Typically, from EBCDIC to ASCII, and numeric fields, packed decimal fields etc are converted to ASCII strings. How is this done? The only way to do an EBCDIC to ASCII conversion is with a program that has knowledge of the record layout. With MediaMerge/PC, details of each record structure are entered and how each field is to be converted can be set. Files with multiple record structures and multiple fields can then be converted on a field-by-field basis to give exactly the correct type of conversion. It is an ideal solution for an EBCDIC and ASCII conversion as all data is retained. Packed decimal fields are normally found on mainframe type applications often Cobol related. RR32 can be used to create Access compatible files or even take ASCII files and create files with packed decimal numbers.

Floating-point numbers are much harder to describe but have the advantage that they can represent a very large range of values including many decimal places. They tend to be 4,8 or 10 bytes in length. Their disadvantage is that the value they represent may not be exact, and so it is possible to get 24.999999 rather than 25. There are various standards for the numbers, but there are also many variations that are platform dependent.

Solutions

eMag has several solutions to the ASCII/EBCDIC problem. Some involve just doing a character conversion, but the most complex is the MM/PC Record Reformatter (RR32) software that allows a structured file to be processed on a field-by-field basis. Several types of numeric field can be processed within the same file.

Download MM/PC for EBCDIC/ASCII conversions and to restore the data to disk
Data conversion solutions

Back to top