//ASCII碼轉成對應的字符串
string s = "4131303232303133";
byte[] buff = new byte[s.Length / 2];
int index = 0;
for (int i = 0; i < s.Length; i += 2)
{
buff[index] = Convert.ToByte(s.Substring(i, 2), 16);
++index;
}
string result = Encoding.Default.GetString(buff);
MessageBox.Show(result);
運行結果:A1022013
//字符串轉成對應的ASCII碼
string s2 = "A1022013";
byte [] ba = System.Text.ASCIIEncoding.Default.GetBytes(s2) ;
StringBuilder sb = new StringBuilder();
foreach (byte b in ba)
{
sb.Append(b.ToString("x"));
}
MessageBox.Show(sb.ToString());
運行結果:4131303232303133