title: Hex To String in Java Performance is too slow
body: <p>I have the following method for my android program, written in Java. </p>
  
  <p>The method takes in a string of hex and returns a string of the same text written in ascii. </p>
  
  <pre><code>public static String hexToString(String hex)
  {
      StringBuilder sb = new StringBuilder();
  
      for (int count = 0; count &lt; hex.length() - 1; count += 2)
      {
          String output = hex.substring(count, (count + 2));    //grab the hex in pairs
  
          int decimal = Integer.parseInt(output, 16);    //convert hex to decimal
  
          sb.append((char)decimal);    //convert the decimal to character
      }
  
      return sb.toString();
  }
  </code></pre>
  
  <p>The method works fine, however my program is very time critical and this method is potentially being called tens of thousands of times. When analysing the slow bits of my program, this method takes up far too much time because of:</p>
  
  <pre><code>Integer.parseInt(output, 16);
  </code></pre>
  
  <p>and </p>
  
  <pre><code>hex.substring(count, (count + 2));
  </code></pre>
  
  <p>In the order of slowest first. </p>
  
  <p>Does anyone know of a faster method of achieving the same thing? </p>