<p>I am looking for a way to convert a long string (from a dump), that represents hex values into a byte array.</p>

<p>I couldn't have phrased it better than the person that posted <a href="http://www.experts-exchange.com/Programming/Programming_Languages/Java/Q_21062554.html" rel="noreferrer">the same question here</a>.</p>

<p>But to keep it original, I'll phrase it my own way: suppose I have a string <code>"00A0BF"</code> that I would like interpreted as the</p>

<pre><code>byte[] {0x00,0xA0,0xBf}
</code></pre>

<p>what should I do?</p>

<p>I am a Java novice and ended up using <code>BigInteger</code> and watching out for leading hex zeros. But I think it is ugly and I am sure I am missing something simple. </p>

The Hex class in commons-codec should do that for you.
http://commons.apache.org/codec/
```
```
import org.apache.commons.codec.binary.Hex;
...
byte[] decoded = Hex.decodeHex("00A0BF");
// 0x00 0xA0 0xBF
```
```