Java Convert via ByteBuffer intsToBytes(int[] n)

Here you can find the source of intsToBytes(int[] n)

Description

ints To Bytes

License

Open Source License

Declaration

public static byte[] intsToBytes(int[] n) 

Method Source Code

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

import java.nio.ByteBuffer;
import java.nio.IntBuffer;

import java.util.List;

public class Main {
    public static byte[] intsToBytes(int[] n) {
        byte[] bytes = new byte[n.length * (Integer.SIZE / 8)];

        ByteBuffer b = ByteBuffer.wrap(bytes);

        b.asIntBuffer().put(n);//from  ww w.  j a va2s. c  o m

        return bytes;
    }

    public static byte[] intsToBytes(List<Integer> n) {
        byte[] bytes = new byte[n.size() * (Integer.SIZE / 8)];

        ByteBuffer b = ByteBuffer.wrap(bytes);
        IntBuffer ib = b.asIntBuffer();

        for (int val : n)
            ib.put(val);

        return bytes;
    }
}

Related

  1. hexToBytes(String hexString)
  2. intArrayFromBytes(byte[] bytes)
  3. intArrayToByteArray(int[] intArray)
  4. intArrayToBytes(Collection values)
  5. intArrayToIntBuffer(int[] data)
  6. IntToBArray(int src)
  7. intToByte(int[] intArray)
  8. intToByteArray(int integer)
  9. intToByteArray(int l)