Getting EBCDIC value of a character in C

ε祈祈猫儿з 提交于 2019-12-13 05:37:50

问题


I need to get the EBCDIC value of a character in C. I don't know how. Do I have to get the ASCII value first then get the EBCDIC value from there? Thanks anyone


回答1:


If you're on a system that uses EBCDIC as the character encoding, you already have it:

char xyzzy = 'A'; // xyzzy is now 0xc1

If your environment is an ASCII one and you simply want the EBCDIC code point, you can just use a lookup table built from both tables, like:

A lookup tables for a system using 8-bit ASCII characters to give you the EBCDIC code points would be something like:

int ebcdicCodePont (unsigned char asciiVal) {
    static int lookup[] = {
        /* 0x00-07 */   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
        /* 0x08-0f */   -1,   -1,   -1,   -1,   -1,   -1,   -1,   -1,
        :
        /* 0x20-27 */ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,
        :
        /* 0x48-4f */ 0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6,
        :
        /* 0x78-7f */ 0xa7, 0xa8, 0xa9,   -1, 0x45,   -1,   -1, 0x07,
    };
    if (asciiVal > 0x7f)
        return -1;
    return lookup[asciiVal];
};


来源:https://stackoverflow.com/questions/22033636/getting-ebcdic-value-of-a-character-in-c

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!