Dave's Brain

Browse - 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; }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.