 public static string HexToASCII(string Msg)    {      byte[] buff = new byte[Msg.Length / 2];      string Message = "";      for (int i = 0; i < buff.Length; i )      {        buff[i] = byte.Parse(Msg.Substring(i * 2, 2),          System.Globalization.NumberStyles.HexNumber);      }      System.Text.Encoding chs = System.Text.Encoding.ASCII;      Message = chs.GetString(buff);      return Message;    }    public static string HexToStr(string Msg)    {      byte[] buff = new byte[Msg.Length / 2];      string Message = "";      for (int i = 0; i < buff.Length; i )      {        buff[i] = byte.Parse(Msg.Substring(i * 2, 2),          System.Globalization.NumberStyles.HexNumber);      }      System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312");      Message = chs.GetString(buff);      return Message;    }    public static string StrToHex(string Msg)    {      byte[] bytes = System.Text.Encoding.Default.GetBytes(Msg);      string str = "";      for (int i = 0; i < bytes.Length; i )      {        str = string.Format("{0:X}", bytes[i]);      }      return str;    }
     public static string HexToASCII(string Msg)    {      byte[] buff = new byte[Msg.Length / 2];      string Message = "";      for (int i = 0; i < buff.Length; i )      {        buff[i] = byte.Parse(Msg.Substring(i * 2, 2),          System.Globalization.NumberStyles.HexNumber);      }      System.Text.Encoding chs = System.Text.Encoding.ASCII;      Message = chs.GetString(buff);      return Message;    }    public static string HexToStr(string Msg)    {      byte[] buff = new byte[Msg.Length / 2];      string Message = "";      for (int i = 0; i < buff.Length; i )      {        buff[i] = byte.Parse(Msg.Substring(i * 2, 2),          System.Globalization.NumberStyles.HexNumber);      }      System.Text.Encoding chs = System.Text.Encoding.GetEncoding("gb2312");      Message = chs.GetString(buff);      return Message;    }    public static string StrToHex(string Msg)    {      byte[] bytes = System.Text.Encoding.Default.GetBytes(Msg);      string str = "";      for (int i = 0; i < bytes.Length; i )      {        str = string.Format("{0:X}", bytes[i]);      }      return str;    }

 
  
					
				
评论