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?

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









Related Tutorials/Questions & Answers:
Convert a string representation of a hex dump to a byte array using Java?
how to convert string to char array in java without using tochararray
Advertisements
How to convert string to byte in Java
convert zip file to byte array
Java convert file to 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 create a zip by using byte array
Convert string into character array
how to convert string to char array in Java
How to convert Arraylist into String Array Java
How to convert java BigDecimal to normal byte array not 2 s complement
create a string from an array using JavaScript
Calculating the checksum of a Byte Array by using Adler32
How to Create a ByteBuffer using Byte Array in java.
difference between java5 and java6 - Java Beginners
ModuleNotFoundError: No module named 'string_to_hex_color'
Java2
Conversion from String to byte
conver byte array to ByteArrayOutputStream
Conversion from byte to String
Array of String using Pointers
how to convert xml string to soap request object using axis1.4?
How ro convert char into string using recursive function in c#??
Convert an Integer type object to a String object
array to string
How to convert String Date to Timestamp in Java?
how to convert string to image in java
string array
array string
array of string
php parse string into array
job submission in cloud computing using gui representation
How to Convert ArrayList to Array?
Byte array to PDF Conversion
Java arraylist to string array
PHP Array to String Conversion
Java insertion sort with string array
string array sort
string array sort
string array sort
string array sort
string array sort
Java file to byte array
Convert Array to List
How to Convert String to Date?
Convert Byte to Hexadecimal
Convert Array to Vector
about java1

Ads