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 create a zip by using 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 convert java BigDecimal to normal byte array not 2 s complement
How to convert Arraylist into String Array Java
conver byte array to ByteArrayOutputStream
Conversion from String to byte
Conversion from byte to String
how to convert string to image in java
How ro convert char into string using recursive function in c#??
ModuleNotFoundError: No module named 'string_to_hex_color'
How to convert String Date to Timestamp in Java?
Array of String using Pointers
How to Convert ArrayList to Array?
Java2
Byte array to PDF Conversion
array string
Java file to byte array
Convert Array to Vector
string array
Java example for Reading file into byte array
How to Convert String to Date?
array of string
job submission in cloud computing using gui representation
Java insertion sort with string array
convert string to date nsdate
How to convert into to String in Java?

Ads