Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners Convert a string representation of a hex dump to a byte array using Java?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
Convert a string representation of a hex dump to a byte array using Java?
1 Answer(s)      a year ago
Posted in : Java Beginners


Convert a string representation of a hex dump to a byte array using Java?


Advertisement
View Answers

December 24, 2013 at 4:35 PM


Here is how you can convert a string representation of a hex dump to a byte array in Java.

public static byte[] hexStringToByteArray(String s) {
    int len = s.length();
    byte[] data = new byte[len / 2];
    for (int i = 0; i < len; i += 2) {
        data[i / 2] = (byte) ((Character.digit(s.charAt(i), 16) << 4)
                             + Character.digit(s.charAt(i+1), 16));
    }
    return data;
}


Related Tutorials/Questions & Answers:
Advertisements
Advertisements
 

 

 

DMCA.com