title: Is this the best way to convert String hex to bytes?
body: <p>Is this the best way to convert String hex to bytes?
  Or can you think a shorter/simpler?</p>
  
  <pre><code>public static byte[] hexToBytes(String hex) {
  return hexToBytes(hex.toCharArray());
  }
  
  public static byte[] hexToBytes(char[] hex) {
  int length = hex.length / 2;
  byte[] raw = new byte[length];
  for (int i = 0; i &lt; length; i++) {
      int high = Character.digit(hex[i * 2], 16);
      int low = Character.digit(hex[i * 2 + 1], 16);
      int value = (high &lt;&lt; 4) | low;
      if (value &gt; 127)
      value -= 256;
      raw[i] = (byte) value;
  }
  return raw;
  }
  </code></pre>