问题
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