Android Byte Array to Int Convert toIntegerArray(byte[] input, int offset, int len, int[] output, int outputOffset)

Here you can find the source of toIntegerArray(byte[] input, int offset, int len, int[] output, int outputOffset)

Description

to Integer Array

License

Apache License

Declaration

public static void toIntegerArray(byte[] input, int offset, int len,
            int[] output, int outputOffset) 

Method Source Code

//package com.java2s;
/**/*from   w  w w  . j a  va2  s.  c  o m*/
 * Source obtained from crypto-gwt. Apache 2 License.
 * https://code.google.com/p/crypto-gwt/source/browse/crypto-gwt/src/main/java/com/googlecode/
 * cryptogwt/util/ByteArrayUtils.java
 */

public class Main {
    public static int[] toIntegerArray(byte[] input, int offset, int len) {
        assert len % 4 == 0 : "Must be a multiple of 4 bytes";
        int[] result = new int[len / 4];
        toIntegerArray(input, offset, len, result, 0);
        return result;
    }

    public static void toIntegerArray(byte[] input, int offset, int len,
            int[] output, int outputOffset) {
        assert len % 4 == 0 : "Must be a multiple of 4 bytes";
        int outputLen = len / 4;
        assert offset + outputLen < output.length : "Output buffer too short";
        for (int i = outputOffset; i < outputOffset + outputLen; i++) {
            output[i] = toInteger(input, offset);
            offset += 4;
        }
    }

    public static int toInteger(byte[] input) {
        return toInteger(input, 0);
    }

    private static int toInteger(byte[] input, int offset) {
        assert offset + 4 <= input.length : "Invalid length "
                + input.length;
        return ((input[offset++] & 0xff) << 24)
                | ((input[offset++] & 0xff) << 16)
                | ((input[offset++] & 0xff) << 8)
                | ((input[offset++] & 0xff));
    }
}

Related

  1. bytes2int(byte[] data)
  2. byte2int(byte[] b)
  3. byteArray2Int(byte[] bs)
  4. byteArrayToInt(byte[] b)
  5. toIntegerArray(byte[] input, int offset, int len)
  6. toInt(byte[] bytes)
  7. toInteger(byte[] input)
  8. toInteger(byte[] input, int offset)
  9. readInt(byte[] buff, int pos)