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



Home Answers Viewqa Java-Beginners How do I initialize a byte array in Java?
Login         

View Questions and Answers by Category

Advertisements


 
Have Programming Question? Ask it here!
 
 
 


Java Coder
How do I initialize a byte array in Java?
1 Answer(s)      10 months ago
Posted in : Java Beginners


How do I initialize a byte array in Java?


Advertisement
View Answers

December 24, 2013 at 3:59 PM


byte[] CDRIVES = hexStringToByteArray("e04fd020ea3a6910a2d808002b30309d");

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

Java convert file to byte array : Example Java Array Initialization: Example



Related Tutorials/Questions & Answers:
Advertisements
 

 

 

DMCA.com