Here you can find the source of intsToBytes(int[] data)
Parameter | Description |
---|---|
data | an integer array of arbitrary size |
public static byte[] intsToBytes(int[] data)
//package com.java2s; //License from project: Open Source License public class Main { /**/*from w ww. j a v a 2 s . co m*/ * Convert an array of integers into a new array of bytes. The order of 4 * bytes each is reversed after splitting the integers into bytes. * * @param data * an integer array of arbitrary size * @return a byte array */ public static byte[] intsToBytes(int[] data) { byte[] b = new byte[data.length * 4]; for (int i = 0; i < data.length; i++) { b[i * 4] = (byte) (data[i] & 0xFF); b[i * 4 + 1] = (byte) ((data[i] >> 8) & 0xFF); b[i * 4 + 2] = (byte) ((data[i] >> 16) & 0xFF); b[i * 4 + 3] = (byte) ((data[i] >> 24) & 0xFF); } return b; } }