PGTS PGTS Pty. Ltd.   ACN: 007 008 568

point Site Navigation

point Other Blog Threads



  Valid HTML 4.01 Transitional

   Give Windows The Boot!
   And Say Goodbye To Viruses!

   Ubuntu

   If you own a netbook/laptop~
   Download Ubuntu Netbook!






PGTS Humble Blog

Thread: Tips/Tricks For Programming etc

Author Image Gerry Patterson. The world's most humble blogger
There are 10 types of people in the world. Those who understand binary and those who don't.

Simple EBCDIC Translation


Chronogical Blog Entries:



Date: Fri, 13 Jun 2008 13:43:44 +1000

Sometimes I need to quickly translate EBCDIC to ASCII. There are several very powerful efficient CPAN packages to do this in perl. However if you are using a workstation, sometimes you need access to the system libraries to install these packages. For this reason it sometimes is not possible to install a translation package. This is especially true for Windows computers within a corporate environment. I may be developing software on my own workstation, which is crammed with every utility imaginable (and is probably running cygwin). But the final target is a minimal host with only the basic ActiveState perl install. And I would need to negotiate through various support groups in order to have my new package installed along with the perl script.

In these situations I include the following rough translation subroutine at the top of my code:
my @ebcdic_tbl = (
#   0      1      2      3      4      5      6      7      8      9      A      B      C      D      E      F
"\x00","\x01","\x02","\x03","\x9C","\x09","\x86","\x7F","\x97","\x8D","\x8E","\x0B","\x0C","\x0D","\x0E","\x0F",
"\x10","\x11","\x12","\x13","\x9D","\x85","\x08","\x87","\x18","\x19","\x92","\x8F","\x1C","\x1D","\x1E","\x1F",
"\x80","\x81","\x82","\x83","\x84","\x0A","\x17","\x1B","\x88","\x89","\x8A","\x8B","\x8C","\x05","\x06","\x07",
"\x90","\x91","\x16","\x93","\x94","\x95","\x96","\x04","\x98","\x99","\x9A","\x9B","\x14","\x15","\x9E","\x1A",
"\x20","\xA0","\xE2","\xE4","\xE0","\xE1","\xE3","\xE5","\xE7","\xF1","\xA2","\x2E","\x3C","\x28","\x2B","\x7C",
"\x26","\xE9","\xEA","\xEB","\xE8","\xED","\xEE","\xEF","\xEC","\xDF","\x21","\x24","\x2A","\x29","\x3B","\xAC",
"\x2D","\x2F","\xC2","\xC4","\xC0","\xC1","\xC3","\xC5","\xC7","\xD1","\xA6","\x2C","\x25","\x5F","\x3E","\x3F",
"\xF8","\xC9","\xCA","\xCB","\xC8","\xCD","\xCE","\xCF","\xCC","\x60","\x3A","\x23","\x40","\x27","\x3D","\x22",
"\xD8","\x61","\x62","\x63","\x64","\x65","\x66","\x67","\x68","\x69","\xAB","\xBB","\xF0","\xFD","\xFE","\xB1",
"\xB0","\x6A","\x6B","\x6C","\x6D","\x6E","\x6F","\x70","\x71","\x72","\xAA","\xBA","\xE6","\xB8","\xC6","\xA4",
"\xB5","\x7E","\x73","\x74","\x75","\x76","\x77","\x78","\x79","\x7A","\xA1","\xBF","\xD0","\xDD","\xDE","\xAE",
"\x5E","\xA3","\xA5","\xB7","\xA9","\xA7","\xB6","\xBC","\xBD","\xBE","\x5B","\x5D","\xAF","\xA8","\xB4","\xD7",
"\x7B","\x41","\x42","\x43","\x44","\x45","\x46","\x47","\x48","\x49","\xAD","\xF4","\xF6","\xF2","\xF3","\xF5",
"\x7D","\x4A","\x4B","\x4C","\x4D","\x4E","\x4F","\x50","\x51","\x52","\xB9","\xFB","\xFC","\xF9","\xFA","\xFF",
"\x5C","\xF7","\x53","\x54","\x55","\x56","\x57","\x58","\x59","\x5A","\xB2","\xD4","\xD6","\xD2","\xD3","\xD5",
"\x30","\x31","\x32","\x33","\x34","\x35","\x36","\x37","\x38","\x39","\xB3","\xDB","\xDC","\xD9","\xDA","\x9F"
);
sub ebc2asc {
        my $ret = "";
        foreach my $c(split('',$_[0])) {
                $ret .= $ebcdic_tbl[ord $c];
        }
        return $ret;
}

# ------------------------------------------------------------------------

It doesn't look pretty, but it works. To use it, call it as follows:

        my $ascii_string = ebc2asc($bar);

Where $bar contains the EBCDIC string.

This is actually a modified version of a C program I used to use for such translations.


Other Blog Posts In This Thread:

Copyright     2008, Gerry Patterson. All Rights Reserved.