How to covert hex string to byte array?
<blockquote>
  <p><strong>Possible Duplicate:</strong><br>
  <a href="http://stackoverflow.com/questions/140131/convert-a-string-representation-of-a-hex-dump-to-a-byte-array-using-java">Convert a string representation of a hex dump to a byte array using Java?</a>  </p>
</blockquote>



<p>I am trying to convert a hex string "FFFFFFFFFFFFFFFF" into byte array with size 8</p>

<p>the result should be </p>

<pre><code>byte[] mKey =  { (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF,
        (byte) 0xFF, (byte) 0xFF, (byte) 0xFF, (byte) 0xFF };
</code></pre>

<p>I have tried the for loop </p>

<pre><code>public static byte[] HexString2Bytes(String src) {
    byte[] res = new byte[8];
    for (int i = 0; i &lt; 16; i = i + 2) {
        res[i] = convertToByte(src.substring(i, i + 2));
    }
    return res;
}
</code></pre>

<p>the problem is, I don't know how to implement the method convertToByte() to convert a hex string, like "FF" to 0xFF, please help, thanks.</p>
