This function converts an one-dimensional array of bytes into a one-dimensional array of int - Java Collection Framework

Java examples for Collection Framework:Array Convert

Description

This function converts an one-dimensional array of bytes into a one-dimensional array of int

Demo Code



public class Main{
    public static void main(String[] argv) throws Exception{
        byte[] in = new byte[]{34,35,36,37,37,37,67,68,69};
        System.out.println(java.util.Arrays.toString(convertArraytoInt(in)));
    }//from w ww.  j ava 2 s  . c om
    /**
     * This function converts an one-dimensional array of bytes into a
     * one-dimensional array of int
     * 
     * @param in
     *            the array to be converted
     * @return out the one-dimensional int-array that corresponds the input
     */
    public static int[] convertArraytoInt(byte[] in) {
        int[] out = new int[in.length];
        for (int i = 0; i < in.length; i++) {
            out[i] = in[i] & GF2Field.MASK;
        }
        return out;
    }
}

Related Tutorials