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

Ads
 

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

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

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

Ads









Related Tutorials/Questions & Answers:
Convert a string representation of a hex dump to a byte array using Java?
How to convert string to byte in Java
Advertisements
convert zip file to byte array
Java convert file to byte array
how to convert ACSII to HEX
How do I change a large string into hex and then into byte so that SHA1 can be applied to it?
how to create a zip by using byte array
Convert Array to String
How to convert java BigDecimal to normal byte array not 2 s complement
How to convert Arraylist into String Array Java
Convert string into character array
Calculating the checksum of a Byte Array by using Adler32
How to Create a ByteBuffer using Byte Array in java.
conver byte array to ByteArrayOutputStream
difference between java5 and java6 - Java Beginners
create a string from an array using JavaScript
Conversion from String to byte
Java2
Conversion from byte to String
how to convert xml string to soap request object using axis1.4?
how to convert string to image in java
How ro convert char into string using recursive function in c#??
How to convert String Date to Timestamp in Java?
Convert an Integer type object to a String object
Convert Byte to Hexadecimal
Convert Char To Byte
Byte array to PDF Conversion
job submission in cloud computing using gui representation
How to Convert ArrayList to Array?
Convert Long To Byte
Array of String using Pointers

Ads