我接到一个任务:将C#的代码翻译成Java代码,实现的功能是将GBK转码为EBCDIC码。但是遇到麻烦了,里面大量的byte类型的16进制的字节码,由于C#中的byte的取值范围是0~255,Java中的byte取值范围是-128~127,我打算一次性的将C#中的16进制byte转为10进制的,然后一次性地全部减去128,再转换为java的16进制byte,我需要一个这样的方法,求好心的朋友帮忙,谢了。下面是段C#的代码,例如
#region 码制转换对照表
/// <summary>
/// 码制转换对照表
/// </summary>
private static byte[] cAsciiEbcdic =
{
0x00, 0x10, 0x20, 0x30, 0x70, 0x80, 0x90, 0x01,
0x11, 0x21, 0x31, 0x41, 0x51, 0x71, 0xB1, 0xE1,
0x02, 0x12, 0x22, 0x32, 0x42, 0x52, 0x62, 0x72,
0xB2, 0x03, 0x13, 0x23, 0x33, 0x43, 0x53, 0x63,
0x40, 0x5A, 0x7F, 0x7B, 0xE0, 0x6C, 0x50, 0x7D,
0x4D, 0x5D, 0x5C, 0x4E, 0x6B, 0x60, 0x4B, 0x61,
0xF0, 0xF1, 0xF2, 0xF3, 0xF4, 0xF5, 0xF6, 0xF7,
0xF8, 0xF9, 0x7A, 0x5E, 0x4C, 0x7E, 0x6E, 0x6F,
0x7C, 0xC1, 0xC2, 0xC3, 0xC4, 0xC5, 0xC6, 0xC7,
0xC8, 0xC9, 0xD1, 0xD2, 0xD3, 0xD4, 0xD5, 0xD6,
0xD7, 0xD8, 0xD9, 0xE2, 0xE3, 0xE4, 0xE5, 0xE6,
0xE7, 0xE8, 0xE9, 0xBA, 0xB2, 0xBB/* 0xB0->0xBB*/, 0xB0, 0x6D,//0xA0修改为0xBA 0x5f->0xb0 5b->b2
0x79, 0x81, 0x82, 0x83, 0x84, 0x85, 0x86, 0x87,
0x88, 0x89, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96,
0x97, 0x98, 0x99, 0xA2, 0xA3, 0xA4, 0xA5, 0xA6,
0xA7, 0xA8, 0xA9, 0xC0, 0X4F, 0xD0, 0xA0, 0x73,// 将0x6A修改为0X4F, 将0xA1->0xA0
0x4A, 0x4F, 0xB3, 0x04, 0x14, 0x24, 0x34, 0x44,
0x54, 0x64, 0x74, 0xB4, 0x05, 0x15, 0x25, 0x35,
0x45, 0x55, 0x65, 0x75, 0xB5, 0x06, 0x16, 0x26,
0x36, 0x46, 0x56, 0x66, 0x76, 0xB6, 0x07, 0x17,
0x27, 0x37, 0x47, 0x57, 0x67, 0x77, 0xB7, 0x08,
0x18, 0x28, 0x38, 0x48, 0x58, 0x68, 0x78, 0xB8,
0x09, 0x19, 0x29, 0x39, 0x49, 0x59, 0x69, 0xB9,
0x0A, 0x1A, 0x2A, 0x3A, 0x8A, 0x9A, 0xAA, 0xBA,
0xCA, 0xDA, 0xEA, 0xFA, 0x0B, 0x1B, 0x2B, 0x3B,
0x8B, 0x9B, 0xAB, 0xBB, 0xCB, 0xDB, 0xEB, 0xFB,
0x0C, 0x1C, 0x2C, 0x3C, 0x8C, 0x9C, 0xAC, 0xBC,
0xCC, 0xDC, 0xEC, 0xFC, 0x0D, 0x1D, 0x2D, 0x3D,
0x8D, 0x9D, 0xAD, 0xBD, 0xCD, 0xDD, 0xED, 0xFD,
0x0E, 0x1E, 0x2E, 0x3E, 0x8E, 0x9E, 0xAE, 0xBE,
0xCE, 0xDE, 0xEE, 0xFE, 0x0F, 0x1F, 0x2F, 0x3F,
0x8F, 0x9F, 0xAF, 0xBF, 0xCF, 0xDF, 0xEF, 0xFF
};
------解决思路----------------------
位移操作即可
------解决思路----------------------
感觉上 直接强转成byte 不就行了,转码应该进行的是位预算,与这个字节被解释成什么值没什么关系吧
类似像这样
(byte)0x00, (byte)0x10, (byte)0x20, (byte)0x30, (byte)0x70, (byte)0x80, (byte)0x90, (byte)0x01,
(byte)0x11, (byte)0x21, (byte)0x31, (byte)0x41, (byte)0x51, (byte)0x71, (byte)0xB1, (byte)0xE1,
(byte)0x02, (byte)0x12, (byte)0x22, (byte)0x32, (byte)0x42, (byte)0x52, (byte)0x62, (byte)0x72,
(byte)0xB2, (byte)0x03, (byte)0x13, (byte)0x23, (byte)0x33, (byte)0x43, (byte)0x53, (byte)0x63,
(byte)0x40, (byte)0x5A, (byte)0x7F, (byte)0x7B, (byte)0xE0, (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,