先上代码,很简单,仅涉及一些字符转换,e2aTable存放的是对应字节的对照表,借用了网上找到的,核对了下IBM官方提供一个转码表,基本一致:
///
/// Convert EBCDIC bytes to ASCII UTF-8 String
/// Convert Table "https://www.ibm.com/support/knowledgecenter/en/SSZJPZ_11.3.0/com.ibm.swg.im.iis.ds.parjob.adref.doc/topics/r_deeadvrf_EBCDIC_to_ASCII.html"
///
/// bytes array
/// offset
/// length
///
public static string EbcdicToAscii(byte[] data, int offset, int length)
{
int[] e2aTable = new int[256]
{
0, 1, 2, 3,156, 9,134,127,151,141,142, 11, 12, 13, 14, 15,
16, 17, 18, 19,157,133, 8,135, 24, 25,146,143, 28, 29, 30, 31,
128,129,130,131,132, 10, 23, 27,136,137,138,139,140, 5, 6, 7,
144,145, 22,147,148,149,150, 4,152,153,154,155, 20, 21,158, 26,
32,160,161,162,163,164,165,166,167,168, 91, 46, 60