Code
1 #region 把16进制字符串转换成普通字符串
2
3 private string HexStrToStr(string text)
4 {
5 string result = "";
6 byte[] bytes = new byte[text.Length / 2];
7 int i = 0, r = 0;
8 while (i < text.Length)
9 {
10 bytes[r] = byte.Parse(text.Substring(i, 2), System.Globalization.NumberStyles.HexNumber);
11 i += 2;
12 r++;
13 }
14 result = Encoding.GetEncoding("GB2312").GetString(bytes);
15 return result;
16 }
17
18 #endregion
19
20 #region 把字符串转换成16进制字符串
21
22 private string ChangeStrToHex(string text)
23 {
24 string result = string.Empty;
25 char[] chars = text.ToCharArray();
26 if (chars != null)
27 {
28 foreach (char c in chars)
29 {
30 int letter = Convert.ToInt32(c);
31 result += String.Format("{0:X}", letter);
32 }
33 }
34 return result;
35 }
36
37 #endregion
普通字符串和16进制字符串相互转换
Code