Continue from my last post about Convert EBCDIC to Ascii Convert, now I try to create a program with C/C++ to convert Ascii to EBCDIC (ascii to ebcdic converter). Create a file main.c and copy this code :
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
/* * main.c * * Created on: Mar 22, 2011 * Author: toto */ #include <stdlib.h> #include <stdio.h> unsigned char ascii_to_ebc_table(unsigned char ascii); int main(int argc, char **argv) { int n; int i; unsigned char ebc; n = 4; unsigned char data[4] = {84, 104, 105, 115}; for(i=0; i<n; i++) { ebc = ascii_to_ebc_table(data[i]); printf("%c(%i) --> %c(%i) \n", data[i], data[i], ebc, ebc); } return (1); } unsigned char ascii_to_ebc_table(unsigned char ascii) { unsigned char ebcd; static char tt[256]= { 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x4F,0x7F,0x7B,0x5B,0x6C,0x50,0x7D, /* !"#$%&' */ 0x4D,0x5D,0x5C,0x4E,0x6B,0x60,0x4B,0x61, /* ()*+,-./ */ 0xF0,0xF1,0xF2,0xF3,0xF4,0xF5,0xF6,0xF7, /* 01234567 */ 0xF8,0xF9,0x7A,0x5E,0x4C,0x7E,0x6E,0x6F, /* 89:;<=>? */ 0x7C,0xC1,0xC2,0xC3,0xC4,0xC5,0xC6,0xC7, /* @ABCDEFG */ 0xC8,0xC9,0xD1,0xD2,0xD3,0xD4,0xD5,0xD6, /* HIJKLMNO */ 0xD7,0xD8,0xD9,0xE2,0xE3,0xE4,0xE5,0xE6, /* PQRSTUVW */ 0xE7,0xE8,0xE9,0x4A,0xE0,0x5A,0x5F,0x6D, /* XYZ[\]^_ */ 0x79,0x81,0x82,0x83,0x84,0x85,0x86,0x87, /* `abcdefg */ 0x88,0x89,0x91,0x92,0x93,0x94,0x95,0x96, /* hijklmno */ 0x97,0x98,0x99,0xA2,0xA3,0xA4,0xA5,0xA6, /* pqrstuvw */ 0xA7,0xA8,0xA9,0xC0,0x6A,0xD0,0xA1,0x40, /* xyz{|}~ */ 0xB9,0xBA,0xED,0xBF,0xBC,0xBD,0xEC,0xFA, /* */ 0xCB,0xCC,0xCD,0xCE,0xCF,0xDA,0xDB,0xDC, /* */ 0xDE,0xDF,0xEA,0xEB,0xBE,0xCA,0xBB,0xFE, /* */ 0xFB,0xFD,0x7d,0xEF,0xEE,0xFC,0xB8,0xDD, /* */ 0x77,0x78,0xAF,0x8D,0x8A,0x8B,0xAE,0xB2, /* */ 0x8F,0x90,0x9A,0x9B,0x9C,0x9D,0x9E,0x9F, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0xAA,0xAB,0xAC,0xAD,0x8C,0x8E,0x80,0xB6, /* ���� */ 0xB3,0xB5,0xB7,0xB1,0xB0,0xB4,0x76,0xA0, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40, /* */ 0x40,0x40,0x40,0x40,0x40,0x40,0x40,0x40 /* */ }; ebcd=tt[ascii]; return (ebcd); } |
We can compile this code Ascii to EBCDIC Converter with command :
gcc main.c -o ascii2ebcdic
This is output program for Ascii to EBCDIC Converter :
1 2 3 4 |
T(84) --> �(227) h(104) --> �(136) i(105) --> �(137) s(115) --> �(162) |
You can read about convert ebcdic to ascii at here.
My name is Toto Sugito. This is my notes when I try something. Maybe, this is NOT THE BEST SOLUTION for your problems. If you have other method or idea that better with my post, please share in this blog. Thank for visiting my site.
That’s way more cleevr than I was expecting. Thanks!