=0x24){first+=0xe;bytes[0]=" />
文档库 最新最全的文档下载
当前位置:文档库 › eterm汉字编码与解码

eterm汉字编码与解码

public byte[] GetChineseCode(string chineseChar)
{
var bytes = new byte[2];
var byteArr = Encoding.GetEncoding("gb2312").GetBytes(chineseChar);
var first = (byte)(byteArr[0] + 0x72);
if (first >= 0x24)
{
first += 0xe;
bytes[0] = first;
}

var second = (byte)(byteArr[1] + 0x80);
bytes[1] = second;
if (second >= 0x2f)
{
if (second <= 0x32)
{
second -= 0xa;
bytes[1] = bytes[0];
bytes[0] = second;
}
}
return bytes;
}

private byte[] GetChineseCodeID(byte[] chinesec)
{
var judge = 0x2f <= chinesec[0] + 0xa && chinesec[0] + 0xa <= 0x32;
var first =judge ? chinesec[1] : chinesec[0];
var second = judge? chinesec[0] : chinesec[1];
first = (byte)first - 0xe >= 0x24 ? (byte)(first - 0xe) : first;
first = (byte)(first - 0x72);
second = judge? (byte)(second + 0xa) : second;
second = (byte)(second - 0x80);
return new byte[] { first, second };
}

相关文档