How do I initialize a byte array in Java?

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









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 do I upgrade mysql?
How can I do it? .click();
difference between java5 and java6 - Java Beginners
Java2
how to create a zip by using byte array
How do you get the size of an array in Python
how do i solve this problem?
how do i solve this question?
How do i do the coding for 'leaving a comment' in java
conver byte array to ByteArrayOutputStream
How do I decompile Java class files?
How do I compare strings in Java?
about java1
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
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?
Byte array to PDF Conversion
How do I study big data?
How do I start machine learning with Python? What should I do if I am a beginner?
How to convert java BigDecimal to normal byte array not 2 s complement
How do I generate random number?
How do I do this program? I'm new to Java programming...
how do i grab the url in php?
How do I start learning MongoDB?
How do I download urllib3 for python 2.7
How do I become a machine learning engineer?
How do I start data mining?
How do I learn Python data science?
How do I start a data mining company?
How do I get a job in AI field?
How do I start learning AI?
How do I become an AI engineer?
How can I do data science course?
How do I become a data scientist in India?
How do I prepare for a data scientist interview?
How do I become a data scientist for free?
How do I start a data science career?
How do I become a data scientist in 2020?
How do I start learning machine learning?

Ads