byte[] cnByte = Encoding.GetEncoding("GB2312").GetBytes(tempStr);
//ASCII 转中文、字符串
/string cnStr = Encoding.GetEncoding("GB2312").GetString(cnByte);
/// <summary>
/// 字符串转字节数组
/// </summary>
/// <param name="s"></param>
/// <returns></returns>
public static byte[] HexStringToByteArray(string s)
{
s = s.Replace(" ", "");
byte[] buffer = new byte[s.Length / 2];
for (int i = 0; i < s.Length; i += 2)
buffer[i / 2] = (byte)Convert.ToByte(s.Substring(i, 2), 16);
return buffer;
}
//字节数组转换十六进制字符串
public static string ByteArrayToHexString(byte[] data)
{
StringBuilder sb = new StringBuilder(data.Length * 3);
foreach (byte b in data)
sb.Append(Convert.ToString(b, 16).PadLeft(2, '0').PadRight(3, ' '));
return sb.ToString().ToUpper();
}
后续将继续汇总……