EBCDIC、ASCII与EBCDIC的关系及相互转化
EBCDIC (Extended Binary Coded Decimal Interchange Code) 为国际商用机器公司(IBM)于1963年-64年间推出的字符编码表,根据早期打孔机式的二进化十进数(BCD, Binary Coded Decimal)排列而成。
EBCDIC编码中,英文字母不是连续地排列,中间出现多次断续,为撰写程序的人带来了一些困难。
ASCII比EBCDIC后出现,ASCII的编码方式参照了EBCDIC,将英文连了起来,方便了程序员记忆。因此,就连IBM的个人计算机和工作站操作系统也不使用它们所有的EBCDIC编码。相反的,它们使用文本的工业标准编码,ASCII码。
转化程序允许不同的操作系统从一种编码到另一种编码的转化。
(1)下面是ASCII和EBCDIC的编码转化表。
The following table shows ASCII and EBCDIC character code values along with their decimal,octal, and hexadecimal equivalents. Abreviations, such as NUL and SOH are spelled out at the endof the table, in order of appearance.Table C-1. ASCII/EBCDIC Character SetsASCII EBCDIC Character Code ValuesControl/Graphic Control/Graphic Decimal Octal HexadecimalNUL NUL 0 000 00SOH SOH 1 001 01STX STX 2 002 02ETX ETX 3 003 03EOT PF 4 004 04ENQ HT 5 005 05ACK LC 6 006 06BEL DEL 7 007 07BS 8 010 08HT 9 011 09LF SMM 10 012 0AVT VT 11 013 0BFF FF 12 014 0CCR CR 13 015 0DSO SO 14 016 0ESI SI 15 017 0FDLE DLE 16 020 10DC1 DC1 17 021 11DC2 DC2 18 022 12DC3 TM 19 023 13DC4 RES 20 024 14NAK NL 21 025 15SYN BS 22 026 16ETB IL 23 027 17CAN CAN 24 030 18EM EM 25 031 19SUB CC 26 032 1AESC CU1 27 033 1BFS IFS 28 034 1CGS IGS 29 035 1DRS IRS 30 036 1EUS IUS 31 037 1FSP DS 32 040 20! SOS 33 041 21" FS 34 042 22# 35 043 23$ BYP 36 044 24% LF 37 045 25& ETB 38 046 26' ESC 39 047 27( 40 050 28) 41 051 29* SM 42 052 2A+ CU2 43 053 2B, 44 054 2C- ENQ 45 055 2D. ACK 46 056 2E/ BEL 47 057 2F0 48 060 301 49 061 312 SYN 50 062 323 51 063 334 PN 52 064 345 RS 53 065 356 UC 54 066 367 EOT 55 067 378 56 070 389 57 071 39: 58 072 3A; CU3 59 073 3B< DC4 60 074 3C= NAK 61 075 3D> 62 076 3E? SUB 63 077 3F@ SP 64 100 40A 65 101 41B 66 102 42C 67 103 43D 68 104 44E 69 105 45F 70 106 46G 71 107 47H 72 110 48I 73 111 49J 74 112 4AK . 75 113 4BL < 76 114 4CM ( 77 115 4DN + 78 116 4EO | 79 117 4FP & 80 120 50Q 81 121 51R 82 122 52S 83 123 53T 84 124 54U 85 125 55V 86 126 56W 87 127 57X 88 130 58Y 89 131 59Z ! 90 132 5A[ $ 91 133 5B\ * 92 134 5C] ) 93 135 5D^ ; 94 136 5E_ 95 137 5F` - 96 140 60a / 97 141 61b 98 142 62c 99 143 63d 100 144 64e 101 145 65f 102 146 66g 103 147 67h 104 150 68i 105 151 69j 106 152 6Ak , 107 153 6Bl % 108 154 6Cm _ 109 155 6Dn > 110 156 6Eo ? 111 157 6Fp 112 160 70q 113 161 71r 114 162 72s 115 163 73t 116 164 74u 117 165 75v 118 166 76w 119 167 77x 120 170 78y 121 171 79z : 122 172 7A{ # 123 173 7B| @ 124 174 7C} ' 125 175 7D~ = 126 176 7EDEL " 127 177 7F128 200 80a 129 201 81b 130 202 82c 131 203 83d 132 204 84e 133 205 85f 134 206 86g 135 207 87h 136 210 88i 137 211 89138 212 8A139 213 8B140 214 8C141 215 8D142 216 8E143 217 8Fj 144 220 90k 145 221 91l 146 222 92147 223 93m 148 224 94n 149 225 95o 150 226 96p 151 227 97q 152 230 98r 153 231 99154 232 9A155 233 9B156 234 9C157 235 9D158 236 9E159 237 9F160 240 A0~ 161 241 A1s 162 242 A2t 163 243 A3u 164 244 A4v 165 245 A5w 166 246 A6x 167 247 A7y 168 250 A8z 169 251 A9170 252 AA171 253 AB172 254 AC173 255 AD174 256 AE175 257 AF176 260 B0177 261 B1178 262 B2179 263 B3180 264 B4181 265 B5182 266 B6183 267 B7184 270 B8185 271 B9186 272 BA187 273 BB188 274 BC189 275 BD190 276 BE191 277 BF192 300 C0A 193 301 C1B 194 302 C2C 195 303 C3D 196 304 C4E 197 305 C5F 198 306 C6G 199 307 C7H 200 310 C8I 201 311 C9202 312 CA203 313 CB204 314 CC205 315 CD206 316 CE207 317 CF208 320 D0J 209 321 D1K 210 322 D2L 211 323 D3M 212 324 D4N 213 325 D5O 214 326 D6P 215 327 D7Q 216 330 D8R 217 331 D9218 332 DA219 333 DB220 334 DC221 335 DD222 336 DE223 337 DF\ 224 340 E0225 341 E1S 226 342 E2T 227 343 E3U 228 344 E4V 229 345 E5W 230 346 E6X 231 347 E7Y 232 350 E8Z 233 351 E9234 352 EA235 353 EB236 354 EC237 355 ED238 356 EE239 357 EF0 240 360 F01 241 361 F12 242 362 F23 243 363 F34 244 364 F45 245 365 F56 246 366 F67 247 367 F78 248 370 F89 249 371 F9250 372 FA251 373 FB252 374 FC253 375 FD254 376 FE255 377 FFNUL NullSOH Start of HeadingSTX Start of TextETX End of TextEOT End of TransmissionENQ EnquiryACK acknowledgeBEL BellBS BackspaceHT Horizontal TabulationLF Line FeedVT Vertical TabulationFF Form FeedCR Carriage ReturnSO Shift OutSI Shift InDLE Data Link EscapeDC1 Device Control 1 (X-ON)DC2 Device Control 2DC3 Device Control 3 (X-OFF)DC4 Device Control 4NAK Negative AcknowledgeSYN Synchronous IdleETB End of Transmission BlockCAN CancelEM End of MediumSUB SubstituteESC EscapeFS File SeparatorGS Group SeparatorRS Record SeparatorUS Unit SeparatorSP Space (Blank)DEL Delete
(2)下面提供一个ASCII和EBCDIC转化的Java程序
public static final byte[] EBCDIC2ASCII = new byte[] {(byte)0x0, (byte)0x1, (byte)0x2, (byte)0x3, (byte)0x9C, (byte)0x9, (byte)0x86, (byte)0x7F, (byte)0x97, (byte)0x8D, (byte)0x8E, (byte)0xB, (byte)0xC, (byte)0xD, (byte)0xE, (byte)0xF, (byte)0x10, (byte)0x11, (byte)0x12, (byte)0x13, (byte)0x9D, (byte)0xA, (byte)0x8, (byte)0x87, (byte)0x18, (byte)0x19, (byte)0x92, (byte)0x8F, (byte)0x1C, (byte)0x1D, (byte)0x1E, (byte)0x1F, (byte)0x80, (byte)0x81, (byte)0x82, (byte)0x83, (byte)0x84, (byte)0x85, (byte)0x17, (byte)0x1B, (byte)0x88, (byte)0x89, (byte)0x8A, (byte)0x8B, (byte)0x8C, (byte)0x5, (byte)0x6, (byte)0x7, (byte)0x90, (byte)0x91, (byte)0x16, (byte)0x93, (byte)0x94, (byte)0x95, (byte)0x96, (byte)0x4, (byte)0x98, (byte)0x99, (byte)0x9A, (byte)0x9B, (byte)0x14, (byte)0x15, (byte)0x9E, (byte)0x1A, (byte)0x20, (byte)0xA0, (byte)0xE2, (byte)0xE4, (byte)0xE0, (byte)0xE1, (byte)0xE3, (byte)0xE5, (byte)0xE7, (byte)0xF1, (byte)0xA2, (byte)0x2E, (byte)0x3C, (byte)0x28, (byte)0x2B, (byte)0x7C, (byte)0x26, (byte)0xE9, (byte)0xEA, (byte)0xEB, (byte)0xE8, (byte)0xED, (byte)0xEE, (byte)0xEF, (byte)0xEC, (byte)0xDF, (byte)0x21, (byte)0x24, (byte)0x2A, (byte)0x29, (byte)0x3B, (byte)0x5E, (byte)0x2D, (byte)0x2F, (byte)0xC2, (byte)0xC4, (byte)0xC0, (byte)0xC1, (byte)0xC3, (byte)0xC5, (byte)0xC7, (byte)0xD1, (byte)0xA6, (byte)0x2C, (byte)0x25, (byte)0x5F, (byte)0x3E, (byte)0x3F, (byte)0xF8, (byte)0xC9, (byte)0xCA, (byte)0xCB, (byte)0xC8, (byte)0xCD, (byte)0xCE, (byte)0xCF, (byte)0xCC, (byte)0x60, (byte)0x3A, (byte)0x23, (byte)0x40, (byte)0x27, (byte)0x3D, (byte)0x22, (byte)0xD8, (byte)0x61, (byte)0x62, (byte)0x63, (byte)0x64, (byte)0x65, (byte)0x66, (byte)0x67, (byte)0x68, (byte)0x69, (byte)0xAB, (byte)0xBB, (byte)0xF0, (byte)0xFD, (byte)0xFE, (byte)0xB1, (byte)0xB0, (byte)0x6A, (byte)0x6B, (byte)0x6C, (byte)0x6D, (byte)0x6E, (byte)0x6F, (byte)0x70, (byte)0x71, (byte)0x72, (byte)0xAA, (byte)0xBA, (byte)0xE6, (byte)0xB8, (byte)0xC6, (byte)0xA4, (byte)0xB5, (byte)0x7E, (byte)0x73, (byte)0x74, (byte)0x75, (byte)0x76, (byte)0x77, (byte)0x78, (byte)0x79, (byte)0x7A, (byte)0xA1, (byte)0xBF, (byte)0xD0, (byte)0x5B, (byte)0xDE, (byte)0xAE, (byte)0xAC, (byte)0xA3, (byte)0xA5, (byte)0xB7, (byte)0xA9, (byte)0xA7, (byte)0xB6, (byte)0xBC, (byte)0xBD, (byte)0xBE, (byte)0xDD, (byte)0xA8, (byte)0xAF, (byte)0x5D, (byte)0xB4, (byte)0xD7, (byte)0x7B, (byte)0x41, (byte)0x42, (byte)0x43, (byte)0x44, (byte)0x45, (byte)0x46, (byte)0x47, (byte)0x48, (byte)0x49, (byte)0xAD, (byte)0xF4, (byte)0xF6, (byte)0xF2, (byte)0xF3, (byte)0xF5, (byte)0x7D, (byte)0x4A, (byte)0x4B, (byte)0x4C, (byte)0x4D, (byte)0x4E, (byte)0x4F, (byte)0x50, (byte)0x51, (byte)0x52, (byte)0xB9, (byte)0xFB, (byte)0xFC, (byte)0xF9, (byte)0xFA, (byte)0xFF, (byte)0x5C, (byte)0xF7, (byte)0x53, (byte)0x54, (byte)0x55, (byte)0x56, (byte)0x57, (byte)0x58, (byte)0x59, (byte)0x5A, (byte)0xB2, (byte)0xD4, (byte)0xD6, (byte)0xD2, (byte)0xD3, (byte)0xD5, (byte)0x30, (byte)0x31, (byte)0x32, (byte)0x33, (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x37, (byte)0x38, (byte)0x39, (byte)0xB3, (byte)0xDB, (byte)0xDC, (byte)0xD9, (byte)0xDA, (byte)0x9F
};
public static final byte[] ASCII2EBCDIC = new byte[] {(byte)0x0, (byte)0x1, (byte)0x2, (byte)0x3, (byte)0x37, (byte)0x2D, (byte)0x2E, (byte)0x2F, (byte)0x16, (byte)0x5, (byte)0x15, (byte)0xB, (byte)0xC, (byte)0xD, (byte)0xE, (byte)0xF, (byte)0x10, (byte)0x11, (byte)0x12, (byte)0x13, (byte)0x3C, (byte)0x3D, (byte)0x32, (byte)0x26, (byte)0x18, (byte)0x19, (byte)0x3F, (byte)0x27, (byte)0x1C, (byte)0x1D, (byte)0x1E, (byte)0x1F, (byte)0x40, (byte)0x5A, (byte)0x7F, (byte)0x7B, (byte)0x5B, (byte)0x6C, (byte)0x50, (byte)0x7D, (byte)0x4D, (byte)0x5D, (byte)0x5C, (byte)0x4E, (byte)0x6B, (byte)0x60, (byte)0x4B, (byte)0x61, (byte)0xF0, (byte)0xF1, (byte)0xF2, (byte)0xF3, (byte)0xF4, (byte)0xF5, (byte)0xF6, (byte)0xF7, (byte)0xF8, (byte)0xF9, (byte)0x7A, (byte)0x5E, (byte)0x4C, (byte)0x7E, (byte)0x6E, (byte)0x6F, (byte)0x7C, (byte)0xC1, (byte)0xC2, (byte)0xC3, (byte)0xC4, (byte)0xC5, (byte)0xC6, (byte)0xC7, (byte)0xC8, (byte)0xC9, (byte)0xD1, (byte)0xD2, (byte)0xD3, (byte)0xD4, (byte)0xD5, (byte)0xD6, (byte)0xD7, (byte)0xD8, (byte)0xD9, (byte)0xE2, (byte)0xE3, (byte)0xE4, (byte)0xE5, (byte)0xE6, (byte)0xE7, (byte)0xE8, (byte)0xE9, (byte)0xAD, (byte)0xE0, (byte)0xBD, (byte)0x5F, (byte)0x6D, (byte)0x79, (byte)0x81, (byte)0x82, (byte)0x83, (byte)0x84, (byte)0x85, (byte)0x86, (byte)0x87, (byte)0x88, (byte)0x89, (byte)0x91, (byte)0x92, (byte)0x93, (byte)0x94, (byte)0x95, (byte)0x96, (byte)0x97, (byte)0x98, (byte)0x99, (byte)0xA2, (byte)0xA3, (byte)0xA4, (byte)0xA5, (byte)0xA6, (byte)0xA7, (byte)0xA8, (byte)0xA9, (byte)0xC0, (byte)0x4F, (byte)0xD0, (byte)0xA1, (byte)0x7, (byte)0x20, (byte)0x21, (byte)0x22, (byte)0x23, (byte)0x24, (byte)0x25, (byte)0x6, (byte)0x17, (byte)0x28, (byte)0x29, (byte)0x2A, (byte)0x2B, (byte)0x2C, (byte)0x9, (byte)0xA, (byte)0x1B, (byte)0x30, (byte)0x31, (byte)0x1A, (byte)0x33, (byte)0x34, (byte)0x35, (byte)0x36, (byte)0x8, (byte)0x38, (byte)0x39, (byte)0x3A, (byte)0x3B, (byte)0x4, (byte)0x14, (byte)0x3E, (byte)0xFF, (byte)0x41, (byte)0xAA, (byte)0x4A, (byte)0xB1, (byte)0x9F, (byte)0xB2, (byte)0x6A, (byte)0xB5, (byte)0xBB, (byte)0xB4, (byte)0x9A, (byte)0x8A, (byte)0xB0, (byte)0xCA, (byte)0xAF, (byte)0xBC, (byte)0x90, (byte)0x8F, (byte)0xEA, (byte)0xFA, (byte)0xBE, (byte)0xA0, (byte)0xB6, (byte)0xB3, (byte)0x9D, (byte)0xDA, (byte)0x9B, (byte)0x8B, (byte)0xB7, (byte)0xB8, (byte)0xB9, (byte)0xAB, (byte)0x64, (byte)0x65, (byte)0x62, (byte)0x66, (byte)0x63, (byte)0x67, (byte)0x9E, (byte)0x68, (byte)0x74, (byte)0x71, (byte)0x72, (byte)0x73, (byte)0x78, (byte)0x75, (byte)0x76, (byte)0x77, (byte)0xAC, (byte)0x69, (byte)0xED, (byte)0xEE, (byte)0xEB, (byte)0xEF, (byte)0xEC, (byte)0xBF, (byte)0x80, (byte)0xFD, (byte)0xFE, (byte)0xFB, (byte)0xFC, (byte)0xBA, (byte)0xAE, (byte)0x59, (byte)0x44, (byte)0x45, (byte)0x42, (byte)0x46, (byte)0x43, (byte)0x47, (byte)0x9C, (byte)0x48, (byte)0x54, (byte)0x51, (byte)0x52, (byte)0x53, (byte)0x58, (byte)0x55, (byte)0x56, (byte)0x57, (byte)0x8C, (byte)0x49, (byte)0xCD, (byte)0xCE, (byte)0xCB, (byte)0xCF, (byte)0xCC, (byte)0xE1, (byte)0x70, (byte)0xDD, (byte)0xDE, (byte)0xDB, (byte)0xDC, (byte)0x8D, (byte)0x8E, (byte)0xDF
};
public static byte[] ebcdicToAsciiBytes(byte[] e, int offset, int len) {byte[] a = new byte[len];for (int i=0; i<len; i++)a[i] = EBCDIC2ASCII[e[offset+i]&0xFF];return a;
}
public static void asciiToEbcdic(String s, byte[] e, int offset) {int len = s.length();for (int i=0; i<len; i++)e[offset + i] = ASCII2EBCDIC[s.charAt(i)&0xFF];
}
(3)在openssl里有个文件ebcdic.c,这个文件也实现了ASCII与IBM的EBCDIC编码的相互转化的方法。
/* crypto/ebcdic.c */#ifndef CHARSET_EBCDIC#include <openssl/e_os2.h>
#if defined(PEDANTIC) || defined(__DECC) || defined(OPENSSL_SYS_MACOSX)
static void *dummy=&dummy;
#endif#else /*CHARSET_EBCDIC*/#include "ebcdic.h"
/* Initial Port for Apache-1.3 by <Martin.Kraemer@Mch.SNI.De>* Adapted for OpenSSL-0.9.4 by <Martin.Kraemer@Mch.SNI.De>*/#ifdef _OSD_POSIX
/*"BS2000 OSD" is a POSIX subsystem on a main frame.It is made by Siemens AG, Germany, for their BS2000 mainframe machines.Within the POSIX subsystem, the same character set was chosen as in"native BS2000", namely EBCDIC. (EDF04)The name "ASCII" in these routines is misleading: actually, conversionis not between EBCDIC and ASCII, but EBCDIC(EDF04) and ISO-8859.1;that means that (western european) national characters are preserved.This table is identical to the one used by rsh/rcp/ftp and other POSIX tools.
*//* Here's the bijective ebcdic-to-ascii table: */
const unsigned char os_toascii[256] = {
/*00*/ 0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f,0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
/*10*/ 0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97,0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
/*20*/ 0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b,0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /*................*/
/*30*/ 0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04,0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /*................*/
/*40*/ 0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5,0xe7, 0xf1, 0x60, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* .........`.<(+|*/
/*50*/ 0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef,0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x9f, /*&.........!$*);.*/
/*60*/ 0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5,0xc7, 0xd1, 0x5e, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /*-/........^,%_>?*/
/*70*/ 0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf,0xcc, 0xa8, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /*..........:#@'="*/
/*80*/ 0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /*.abcdefghi......*/
/*90*/ 0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70,0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /*.jklmnopqr......*/
/*a0*/ 0xb5, 0xaf, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0xdd, 0xde, 0xae, /*..stuvwxyz......*/
/*b0*/ 0xa2, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc,0xbd, 0xbe, 0xac, 0x5b, 0x5c, 0x5d, 0xb4, 0xd7, /*...........[\]..*/
/*c0*/ 0xf9, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47,0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /*.ABCDEFGHI......*/
/*d0*/ 0xa6, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50,0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xdb, 0xfa, 0xff, /*.JKLMNOPQR......*/
/*e0*/ 0xd9, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58,0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /*..STUVWXYZ......*/
/*f0*/ 0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37,0x38, 0x39, 0xb3, 0x7b, 0xdc, 0x7d, 0xda, 0x7e /*0123456789.{.}.~*/
};/* The ascii-to-ebcdic table: */
const unsigned char os_toebcdic[256] = {
/*00*/ 0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f,0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /*................*/
/*10*/ 0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26,0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /*................*/
/*20*/ 0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d,0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */
/*30*/ 0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7,0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /*0123456789:;<=>?*/
/*40*/ 0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7,0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /*@ABCDEFGHIJKLMNO*/
/*50*/ 0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6,0xe7, 0xe8, 0xe9, 0xbb, 0xbc, 0xbd, 0x6a, 0x6d, /*PQRSTUVWXYZ[\]^_*/
/*60*/ 0x4a, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /*`abcdefghijklmno*/
/*70*/ 0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6,0xa7, 0xa8, 0xa9, 0xfb, 0x4f, 0xfd, 0xff, 0x07, /*pqrstuvwxyz{|}~.*/
/*80*/ 0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08,0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /*................*/
/*90*/ 0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17,0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0x5f, /*................*/
/*a0*/ 0x41, 0xaa, 0xb0, 0xb1, 0x9f, 0xb2, 0xd0, 0xb5,0x79, 0xb4, 0x9a, 0x8a, 0xba, 0xca, 0xaf, 0xa1, /*................*/
/*b0*/ 0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3,0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /*................*/
/*c0*/ 0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68,0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /*................*/
/*d0*/ 0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf,0x80, 0xe0, 0xfe, 0xdd, 0xfc, 0xad, 0xae, 0x59, /*................*/
/*e0*/ 0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48,0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /*................*/
/*f0*/ 0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1,0x70, 0xc0, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /*................*/
};#else /*_OSD_POSIX*//*
This code does basic character mapping for IBM's TPF and OS/390 operating systems.
It is a modified version of the BS2000 table.Bijective EBCDIC (character set IBM-1047) to US-ASCII table:
This table is bijective - there are no ambigous or duplicate characters.
*/
const unsigned char os_toascii[256] = {0x00, 0x01, 0x02, 0x03, 0x85, 0x09, 0x86, 0x7f, /* 00-0f: */0x87, 0x8d, 0x8e, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */0x10, 0x11, 0x12, 0x13, 0x8f, 0x0a, 0x08, 0x97, /* 10-1f: */0x18, 0x19, 0x9c, 0x9d, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */0x80, 0x81, 0x82, 0x83, 0x84, 0x92, 0x17, 0x1b, /* 20-2f: */0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x05, 0x06, 0x07, /* ................ */0x90, 0x91, 0x16, 0x93, 0x94, 0x95, 0x96, 0x04, /* 30-3f: */0x98, 0x99, 0x9a, 0x9b, 0x14, 0x15, 0x9e, 0x1a, /* ................ */0x20, 0xa0, 0xe2, 0xe4, 0xe0, 0xe1, 0xe3, 0xe5, /* 40-4f: */0xe7, 0xf1, 0xa2, 0x2e, 0x3c, 0x28, 0x2b, 0x7c, /* ...........<(+| */0x26, 0xe9, 0xea, 0xeb, 0xe8, 0xed, 0xee, 0xef, /* 50-5f: */0xec, 0xdf, 0x21, 0x24, 0x2a, 0x29, 0x3b, 0x5e, /* &.........!$*);^ */0x2d, 0x2f, 0xc2, 0xc4, 0xc0, 0xc1, 0xc3, 0xc5, /* 60-6f: */0xc7, 0xd1, 0xa6, 0x2c, 0x25, 0x5f, 0x3e, 0x3f, /* -/.........,%_>? */0xf8, 0xc9, 0xca, 0xcb, 0xc8, 0xcd, 0xce, 0xcf, /* 70-7f: */0xcc, 0x60, 0x3a, 0x23, 0x40, 0x27, 0x3d, 0x22, /* .........`:#@'=" */0xd8, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67, /* 80-8f: */0x68, 0x69, 0xab, 0xbb, 0xf0, 0xfd, 0xfe, 0xb1, /* .abcdefghi...... */0xb0, 0x6a, 0x6b, 0x6c, 0x6d, 0x6e, 0x6f, 0x70, /* 90-9f: */0x71, 0x72, 0xaa, 0xba, 0xe6, 0xb8, 0xc6, 0xa4, /* .jklmnopqr...... */0xb5, 0x7e, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78, /* a0-af: */0x79, 0x7a, 0xa1, 0xbf, 0xd0, 0x5b, 0xde, 0xae, /* .~stuvwxyz...[.. */0xac, 0xa3, 0xa5, 0xb7, 0xa9, 0xa7, 0xb6, 0xbc, /* b0-bf: */0xbd, 0xbe, 0xdd, 0xa8, 0xaf, 0x5d, 0xb4, 0xd7, /* .............].. */0x7b, 0x41, 0x42, 0x43, 0x44, 0x45, 0x46, 0x47, /* c0-cf: */0x48, 0x49, 0xad, 0xf4, 0xf6, 0xf2, 0xf3, 0xf5, /* {ABCDEFGHI...... */0x7d, 0x4a, 0x4b, 0x4c, 0x4d, 0x4e, 0x4f, 0x50, /* d0-df: */0x51, 0x52, 0xb9, 0xfb, 0xfc, 0xf9, 0xfa, 0xff, /* }JKLMNOPQR...... */0x5c, 0xf7, 0x53, 0x54, 0x55, 0x56, 0x57, 0x58, /* e0-ef: */0x59, 0x5a, 0xb2, 0xd4, 0xd6, 0xd2, 0xd3, 0xd5, /* \.STUVWXYZ...... */0x30, 0x31, 0x32, 0x33, 0x34, 0x35, 0x36, 0x37, /* f0-ff: */0x38, 0x39, 0xb3, 0xdb, 0xdc, 0xd9, 0xda, 0x9f /* 0123456789...... */
};/*
The US-ASCII to EBCDIC (character set IBM-1047) table:
This table is bijective (no ambiguous or duplicate characters)
*/
const unsigned char os_toebcdic[256] = {0x00, 0x01, 0x02, 0x03, 0x37, 0x2d, 0x2e, 0x2f, /* 00-0f: */0x16, 0x05, 0x15, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f, /* ................ */0x10, 0x11, 0x12, 0x13, 0x3c, 0x3d, 0x32, 0x26, /* 10-1f: */0x18, 0x19, 0x3f, 0x27, 0x1c, 0x1d, 0x1e, 0x1f, /* ................ */0x40, 0x5a, 0x7f, 0x7b, 0x5b, 0x6c, 0x50, 0x7d, /* 20-2f: */0x4d, 0x5d, 0x5c, 0x4e, 0x6b, 0x60, 0x4b, 0x61, /* !"#$%&'()*+,-./ */0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, /* 30-3f: */0xf8, 0xf9, 0x7a, 0x5e, 0x4c, 0x7e, 0x6e, 0x6f, /* 0123456789:;<=>? */0x7c, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, /* 40-4f: */0xc8, 0xc9, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, /* @ABCDEFGHIJKLMNO */0xd7, 0xd8, 0xd9, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, /* 50-5f: */0xe7, 0xe8, 0xe9, 0xad, 0xe0, 0xbd, 0x5f, 0x6d, /* PQRSTUVWXYZ[\]^_ */0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87, /* 60-6f: */0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, /* `abcdefghijklmno */0x97, 0x98, 0x99, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, /* 70-7f: */0xa7, 0xa8, 0xa9, 0xc0, 0x4f, 0xd0, 0xa1, 0x07, /* pqrstuvwxyz{|}~. */0x20, 0x21, 0x22, 0x23, 0x24, 0x04, 0x06, 0x08, /* 80-8f: */0x28, 0x29, 0x2a, 0x2b, 0x2c, 0x09, 0x0a, 0x14, /* ................ */0x30, 0x31, 0x25, 0x33, 0x34, 0x35, 0x36, 0x17, /* 90-9f: */0x38, 0x39, 0x3a, 0x3b, 0x1a, 0x1b, 0x3e, 0xff, /* ................ */0x41, 0xaa, 0x4a, 0xb1, 0x9f, 0xb2, 0x6a, 0xb5, /* a0-af: */0xbb, 0xb4, 0x9a, 0x8a, 0xb0, 0xca, 0xaf, 0xbc, /* ................ */0x90, 0x8f, 0xea, 0xfa, 0xbe, 0xa0, 0xb6, 0xb3, /* b0-bf: */0x9d, 0xda, 0x9b, 0x8b, 0xb7, 0xb8, 0xb9, 0xab, /* ................ */0x64, 0x65, 0x62, 0x66, 0x63, 0x67, 0x9e, 0x68, /* c0-cf: */0x74, 0x71, 0x72, 0x73, 0x78, 0x75, 0x76, 0x77, /* ................ */0xac, 0x69, 0xed, 0xee, 0xeb, 0xef, 0xec, 0xbf, /* d0-df: */0x80, 0xfd, 0xfe, 0xfb, 0xfc, 0xba, 0xae, 0x59, /* ................ */0x44, 0x45, 0x42, 0x46, 0x43, 0x47, 0x9c, 0x48, /* e0-ef: */0x54, 0x51, 0x52, 0x53, 0x58, 0x55, 0x56, 0x57, /* ................ */0x8c, 0x49, 0xcd, 0xce, 0xcb, 0xcf, 0xcc, 0xe1, /* f0-ff: */0x70, 0xdd, 0xde, 0xdb, 0xdc, 0x8d, 0x8e, 0xdf /* ................ */
};
#endif /*_OSD_POSIX*//* Translate a memory block from EBCDIC (host charset) to ASCII (net charset)* dest and srce may be identical, or separate memory blocks, but* should not overlap. These functions intentionally have an interface* compatible to memcpy(3).*/void *
ebcdic2ascii(void *dest, const void *srce, size_t count)
{unsigned char *udest = dest;const unsigned char *usrce = srce;while (count-- != 0) {*udest++ = os_toascii[*usrce++];}return dest;
}void *
ascii2ebcdic(void *dest, const void *srce, size_t count)
{unsigned char *udest = dest;const unsigned char *usrce = srce;while (count-- != 0) {*udest++ = os_toebcdic[*usrce++];}return dest;
}#endif
EBCDIC、ASCII与EBCDIC的关系及相互转化相关推荐
- Unicode数据类型(与ANSI关系和相互转化)
Unicode数据类型(与ANSI关系和相互转化) 1,Windows定义Unicode数据类型 WCHAR(Unicode字符) PWSTR(指向Unicode字符串的指针) PCWSTR(指向一个 ...
- EBCDIK,EBCDIC,ASCII,shift JIS間の変換
http://itdoc.hitachi.co.jp/manuals/3020/3020759580/G5950334.HTM#ID01056 转载于:https://www.cnblogs.com/ ...
- java转义字符包括元字符_正则表达式的元字符和转义字符,又及转义字符和ASCII码之间的关系小解...
1.正则表达式的组合 正则表达式由元字符和转义字符组成 元字符有 ^ :断言目标的开始位置(或多行模式下的行首位置) $ :断言目标的介绍位置(或多行模式下的结尾位置) . :匹配除换行符外的其他任何 ...
- php十进制转ascii字符,(5条消息)php ASCII字符和十六进制数之间的相互转化
一:ASCII字符转化为十六进制数 在php中将ASCII字符转化为十六进制数使用到bin2hex函数 语法如下: bin2hex(string) 参数string为需要转化的ASCII字符 实例如下 ...
- php hex2ascii,php ASCII字符和十六进制数之间的相互转化
一:ASCII字符转化为十六进制数 在php中将ASCII字符转化为十六进制数使用到bin2hex函数 语法如下: bin2hex(string) 参数string为需要转化的ASCII字符 实例如下 ...
- java ebcdic编码转换_JAVA实现ASCII码与EBCDIC码的相互转换
import java.io.*; public class coder{ /** * ASCII码对应表 */ private static final String [] ASCII={ &quo ...
- ebcdic编码与ascII编码互转
1:ebcdic编码转ascII编码...... char e2a[256] = { 0, 1, 2, 3,(char)156, 9,(char)134,127,( ...
- AS400所用编码EBCDIC转ASCII
在openssl里有个文件ebcdic.c这个里面就实现了,ebcdic和ascii码的互转,这里记录下. /* crypto/ebcdic.c */#ifndef CHARSET_EBCDIC#in ...
- EBCDIC 与 GBK 的字符编码及其转换(转)
概览 有些用户在使用 AIX 时在字符编码方面遇到一些困惑,请看下面的场景: 1,用户用从 AIX 利用 FTP 客户端登录上 IBM i,切换到某个 Library/File,然后 get 其中的某 ...
最新文章
- python之numpy基础_Python知识普及:Numpy基础操作
- 全球首发免费的MySql for Entity Framework Core
- 【异常(待解决)】org.apache.http.NoHttpResponseException: api.weixin.qq.com:443 failed to respond...
- 三种方法求最长子序列问题
- 17 年安全界老兵,专注打造容器安全能行吗?
- 数据表的新建 修改 删除 mysql
- cpanel java_Cpanel是什么
- php 课程节次周次提取,用PHP写一个最简单的解释器Part5(计算器最后一节,下节开始如何写个脚本语言)...
- Mysql和Oracle实现序列自增
- 论文 结构图 用 visio
- 学术Assignment写作怎么了解文献内容?
- word 保存时 不能保存
- 中国ACM橡胶市场调研与投资预测报告(2022版)
- 20款Adobe AIR小游戏
- Spring Boot框架入门到进阶教程(自学版)
- windows10添加开机自启动项在哪设置?电脑开机自启动怎么设置
- 大数据平台Ambari2.7.4+HDP3.1.4安装(超详细教程)
- Unity可编程渲染管线系列(六)透明度(裁剪与淡化 Clipping and Fading)
- Python---day7作业
- STM32G071RB-NUCLEO和X-NUCLEO-GFX01M1进行GUI开发(一)
热门文章
- MyBatis万能插入语句
- MySQL read_only 与 super_read_only 之间的关系
- mybatis-plus调用自身的 selectById 方法报错:com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: You hav
- Windows变慢原因分析及解决方法
- spark、hadoop、storm、solr、es在车辆分析上的分析与比较
- Java小程序木叶村_恋爱球滚动的天空
- 们指点如果在android平台下开启jbox2d的debugDraw功能
- 树莓派WIFI配置遇到的坑 之 连接不上WIFI
- PYTHON-小白入门-学习顺序
- 矩阵取数游戏(动态规划)