title: Encoding/Decoding hex packet
body: <p>I want to send this hex packet:</p>
  
  <pre><code>00 38 60 dc 00 00 04 33  30 3c 00 00 00 20 63 62 
  39 62 33 61 36 37 34 64  31 36 66 32 31 39 30 64 
  30 34 30 63 30 39 32 66  34 66 38 38 32 62 00 06 
  35 2e 31 33 2e 31 00 00  02 3c
  </code></pre>
  
  <p>so i build the string:</p>
  
  <pre><code>string packet = "003860dc0000" + textbox1.text+ "00000020" + textbox2.text+ "0006" + textbox3.text;
  </code></pre>
  
  <p>then "convert" it to ascii:</p>
  
  <pre><code>conn_str = HexString2Ascii(packet);
  </code></pre>
  
  <p>then i send the packet... but i have this:</p>
  
  <pre><code>00 38 60 **c3 9c** 00 00 04 33  30 3c 00 00 00 20 63 
  62 39 62 33 61 36 37 34 64  31 36 66 32 31 39 30 
  64 30 34 30 63 30 39 32 66  34 66 38 38 32 62 00 
  06 35 2e 31 33 2e 31 00 00  02 3c **0a**
  </code></pre>
  
  <p>why??
  Thank you!
  P.S.
  the function is:</p>
  
  <pre><code>private string HexString2Ascii(string hexString)
  {
       byte[] tmp;
       int j = 0;
       int lenght;
       lenght=hexString.Length-2;
       tmp = new byte[(hexString.Length)/2];
       for (int i = 0; i &lt;= lenght; i += 2)
       {
           tmp[j] =(byte)Convert.ToChar(Int32.Parse(hexString.Substring(i, 2), System.Globalization.NumberStyles.HexNumber));
           j++;
       }
       return Encoding.GetEncoding(1252).GetString(tmp);
  }
  </code></pre>
  
  <hr>
  
  <p>EDIT:
  if i convert directly in byte, the hex packet in coded as string:</p>
  
  <pre><code>00000000  30 30 33 38 36 30 64 63  30 30 30 30 30 34 33 33 003860dc 00000433
  00000010  33 30 33 43 30 30 30 30  30 30 32 30 33 34 33 32 303C0000 00203432
  00000020  36 33 36 33 33 35 33 39  33 32 33 34 36 36 33 39 63633539 32346639
  00000030  36 33 33 39 33 31 33 39  33 30 33 36 33 33 36 35 63393139 30363365
  00000040  33 35 36 33 36 35 36 35  36 35 33 31 33 39 33 38 35636565 65313938
  00000050  36 33 33 31 36 34 33 34  36 33 33 30 30 30 30 36 63316434 63300006
  00000060  33 35 32 65 33 31 33 33  32 65 33 31 30 30 30 30 352e3133 2e310000
  00000070  30 32 33 43                                      023C
  </code></pre>