Programming Tips - How can I convert a hex string into binary data?

Date: 2015jul17 Language: Java Keywords: hexadecimal Q. How can I convert a hex string into binary data? A.
ArrayList<Byte> hexStringToBinaryData(final String hex) { ArrayList<Byte> out = new ArrayList<Byte>(); for (int i = 0; i < hex.length(); i += 2) { out.add((byte) Integer.parseInt(hex.substring(i, i + 2), 16)); } return out; }