在C中获取字符的EBCDIC值 [英] Getting EBCDIC value of a character in C

查看:131
本文介绍了在C中获取字符的EBCDIC值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要获取C中字符的EBCDIC值.我不知道如何.我是否必须先获取ASCII值,然后从那里获取EBCDIC值?谢谢任何人

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

推荐答案

如果您使用的是使用EBCDIC作为字符编码的系统,那么您已经拥有它:

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

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

如果您的环境是ASCII环境,而您只需要EBCDIC代码点,则可以使用从两个表构建的查找表,例如:

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:

使用8位ASCII字符为您提供EBCDIC代码点的系统的查找表如下所示:

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];
};

这篇关于在C中获取字符的EBCDIC值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆