title: .NET Convert from string of Hex values into Unicode characters (Support different code pages)
body: <p>I have a string of Hex values...</p>
  
  <pre><code>String hexString = "8A65";
  </code></pre>
  
  <p>I need to convert this string into their Unicode equivalents. The tricky part is that I need to support different code pages and some code pages have '8A65' = one character whereas other code pages would convert it into two characters.</p>
  
  <p>I have no prior knowledge of which code page I will be using until I need to perform the conversion.</p>
  
  <p>I've tried all sorts of stuff such as</p>
  
  <pre><code>byte[] original = Encoding.Unicode.GetBytes(hexString);
  byte[] conv= Encoding.Convert(Encoding.Unicode, Encoding.GetEncoding(932), orig);
  char[] chars = Encoding.GetEncoding(932).GetChars(conv);
  </code></pre>
  
  <p>Note: code page 932 is Japanese</p>
  
  <p><strong>SOLUTION</strong></p>
  
  <pre><code>string hexString = "8A65";
  int length = hexString.length;
  byte[] bytes = new byte[length / 2];
  
  for (int i = 0; i &lt; length; i += 2)
  {
      bytes[i / 2] = Convert.ToByte(hexString.Substring(i, 2), 16);
  }
  
  char[] chars = Encoding.GetEncoding(932).GetChars(bytes);
  </code></pre>
  
  <p>Thank you pstrjds, you are a life saver!</p>