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 can I initialize the JSONArray and JSON object with data?
how to create a zip by using byte array
How do I upgrade mysql?
How can I do it? .click();
conver byte array to ByteArrayOutputStream
how do i solve this problem?
how do i solve this question?
Java2
How to convert java BigDecimal to normal byte array not 2 s complement
How to Create a ByteBuffer using Byte Array in java.
How do I compare strings in Java?
How do I decompile Java class files?
difference between java5 and java6 - Java Beginners
How do i do the coding for 'leaving a comment' in java
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 learn Spring Framework?
How do I learn Spring Framework?
Byte array to PDF Conversion
How to initialize NSInteger
How do I study big data?
How do I start learning MongoDB?
How do I generate random number?
how do i grab the url in php?
about java1
how do i write a java program for this??
How do I do this program? I'm new to Java programming...

Ads