The BigDecimal class makes this really easy as it has a method toByteArray() that returns exactly what we need. Just need to create a BigDecimal and call the method.
byte bytes = new BigInteger(hexString, 16).toByteArray();
2 Responses to “How to convert a hex string to a byte array?”
Leave a Reply
You must be logged in to post a comment.