Java Integer Array to Byte Array intArrayToBytes(int[] d)

Here you can find the source of intArrayToBytes(int[] d)

Description

int Array To Bytes

License

Open Source License

Declaration

public static byte[] intArrayToBytes(int[] d) 

Method Source Code

//package com.java2s;
/*******************************************************************************
 * Copyright (c) 2013 Oak Ridge National Laboratory.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 ******************************************************************************/

public class Main {
    public static byte[] intArrayToBytes(int[] d) {
        byte[] r = new byte[d.length * 4];
        for (int i = 0; i < d.length; i++) {
            byte[] s = intToBytes(d[i]);
            for (int j = 0; j < 4; j++)
                r[4 * i + j] = s[j];// w  w  w. j av  a 2 s.com
        }
        return r;
    }

    public static byte[] intToBytes(int v) {
        byte[] r = new byte[4];
        for (int i = 0; i < 4; i++) {
            r[i] = (byte) ((v >>> (i * 8)) & 0xFF);
        }
        return r;
    }
}

Related

  1. convertIntArrayToByteArray(int[] myIntArray, int bytesPerInt)
  2. intArray2Bytes(int[] array)
  3. intArrayToByteArray(int[] ai)
  4. intArrayToByteArray(int[] data)
  5. intArrayToByteArray(int[] ints)