title: C# send hex string as hex
body: <p>I have a string and I want to send it as hex value and not ascii value </p>
  
  <p>my string is :</p>
  
  <blockquote>
    <p>0x5C 0x21 0x5C</p>
  </blockquote>
  
  <p>but when I send it I send :</p>
  
  <blockquote>
    <p>30-78-35-43-20-30-78-32-31-20-30-78-35-43</p>
  </blockquote>
  
  <p>how can I over came this?</p>
  
  <p>what am I missing?</p>
  
  <p>this is the full code :</p>
  
  <pre><code>         byte[] address = { 0x30, 0x35 };
            byte[] end = { 0x03 };
  
          string Start = "0x5C 0x21 0x5C 0x73 0x20 0x73";
          for (int x = 0; x &lt; msg.Count; x++)
  
          Console.WriteLine(Start);
  
  
  
          byte[] ByteMessage = encoding.GetBytes(Start);
  
          string HexMessage = BitConverter.ToString(ByteMessage);
  
          var temp = new MemoryStream();
          temp.Write(address, 0, address.Length);
          temp.Write(ByteMessage, 0, ByteMessage.Length);
          temp.Write(end, 0, end.Length);
  
          byte[] testing = temp.ToArray();
          var lrs = gen(testing);
          string lrsString = lrs.ToString("X");
  
  
  
          Console.WriteLine("MSG in HEX -  " + HexMessage);
  
          Console.Write(
                        Encoding.Default.GetString(address) +
  
                        encoding.GetString(ByteMessage) +
  
                        Encoding.Default.GetString(end) +
  
                        );
  
  
  
          byte[] LRS = Encoding.Default.GetBytes(lrsString);
  
          try
          {
  
              sp1.Write(start, 0, start.Length); //send start 
              sp1.Write(testing, 0, testing.Length);//send the all msg 
              sp1.Write(LRS, 0, LRS.Length);//send the Check Sum 
          }
  
          catch (Exception e)
          {
              Console.WriteLine(e);
  
          }
  
          finally
          {
  
          }
  </code></pre>
  
  <p>Thanks ,</p>