Java Byte Array Create toByteArray(int[] data, boolean includeLength)

Here you can find the source of toByteArray(int[] data, boolean includeLength)

Description

to Byte Array

License

Open Source License

Declaration

private static byte[] toByteArray(int[] data, boolean includeLength) 

Method Source Code

//package com.java2s;

public class Main {
    private static byte[] toByteArray(int[] data, boolean includeLength) {
        int n = data.length << 2;

        if (includeLength) {
            int m = data[data.length - 1];
            n -= 4;//w  w w.  j a  v  a 2  s  . co m
            if ((m < n - 3) || (m > n)) {
                return null;
            }
            n = m;
        }
        byte[] result = new byte[n];

        for (int i = 0; i < n; ++i) {
            result[i] = (byte) (data[i >>> 2] >>> ((i & 3) << 3));
        }
        return result;
    }
}

Related

  1. toByteArray(int value)
  2. toByteArray(int value)
  3. toByteArray(int value, int numBytes, byte[] dest, int off)
  4. toByteArray(int[] array)
  5. toByteArray(int[] data)
  6. toByteArray(long hi, long lo)
  7. toByteArray(Long mac)
  8. toByteArray(long value)
  9. toByteArray(long value)