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 string to char array in java without using tochararray
how to create a zip by using byte array
how to convert ACSII to HEX
Convert Array to String
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 string to char array in Java
How to convert Arraylist into String Array Java
Calculating the checksum of a Byte Array by using Adler32
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'
Java2
How to convert String Date to Timestamp in Java?
Convert Byte to Hexadecimal
Array of String using Pointers
Byte array to PDF Conversion
How to Convert ArrayList to Array?
Convert Char To Byte
Java file to byte array
array string
Java example for Reading file into byte array
Convert Long To Byte
Convert Array to List

Ads