字符數組轉換為字符串,字符串轉換為字節,例子如下
char[] ch = new char[str1.Length]; for (int i = 0; i < str1.Length; i++) { ch[i] = str1[i]; } byte[] data = new byte[str1.Length / 2 + 3]; for (int i = 0; i < str1.Length; i = i + 2) { string str2 = ch[i] + "" + ch[i + 1]; int int1 = Convert.ToInt32(str2, 16); data[i / 2] = (Byte)int1; }