How do I initialize a byte array in Java?

Ads
 

How do I initialize a byte array in Java?

How do I initialize a byte array in Java?

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

Ads









Related Tutorials/Questions & Answers:
How do I initialize a byte array in Java?
how do i begin a two dimensional array?
Advertisements
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
How do I upgrade mysql?
conver byte array to ByteArrayOutputStream
How can I do it? .click();
How to convert java BigDecimal to normal byte array not 2 s complement
how do i solve this problem?
how do i solve this question?
Byte array to PDF Conversion
How do I compare strings in Java?
How do I decompile Java class files?
How do i do the coding for 'leaving a comment' in java
How to initialize NSInteger
How do I compile the registration form?
PureStack question---i dont know how to do this
PureStack question---i dont know how to do this
How do I get started with Bootstrap
How do I get started with Bootstrap
Java2
Java file to byte array
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I learn Spring Framework?
How do I study big data?
How do I generate random number?
How do I start learning MongoDB?
how do i grab the url in php?

Ads