Java Convert via ByteBuffer intArrayToByteArray(int[] intArray)

Here you can find the source of intArrayToByteArray(int[] intArray)

Description

Convert from an array of ints to an array of bytes

License

Open Source License

Parameter

Parameter Description
intArray a parameter

Declaration

public static byte[] intArrayToByteArray(int[] intArray) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

import java.nio.ByteBuffer;

import java.nio.IntBuffer;

public class Main {
    /**/*from w  w  w. j  a  v a 2 s  .  com*/
     * Convert from an array of ints to an array of bytes
     * @param intArray
     */
    public static byte[] intArrayToByteArray(int[] intArray) {
        byte[] byteArray = new byte[intArray.length * 4]; // 4 bytes per int
        ByteBuffer byteBuf = ByteBuffer.wrap(byteArray);
        IntBuffer intBuff = byteBuf.asIntBuffer();
        intBuff.put(intArray);
        return byteArray;
    }
}

Related

  1. hexStrToStr(String hexStr)
  2. hexToAscii(byte[] src)
  3. hexToBytes(String hexStr)
  4. hexToBytes(String hexString)
  5. intArrayFromBytes(byte[] bytes)
  6. intArrayToBytes(Collection values)
  7. intArrayToIntBuffer(int[] data)
  8. intsToBytes(int[] n)
  9. IntToBArray(int src)