Java Utililty Methods Byte Array to Int

List of utility methods to do Byte Array to Int

Description

The list of methods to do Byte Array to Int are organized into topic(s).

Method

int[]bytesToIntArr(byte[] arr, int offset, int[] num, int soff, int size)
bytes To Int Arr
for (int i = 0; i < size; ++i) {
    int off = offset + (i * INT_SIZE);
    num[soff + i] = (int) ((arr[off + 0] & 0xFF) << 24) | (int) ((arr[off + 1] & 0xFF) << 16)
            | (int) ((arr[off + 2] & 0xFF) << 8) | (int) ((arr[off + 3] & 0xFF) << 0);
return num;
intbytesToInteger(byte[] b)
Assemble four bytes to an int value, make sure that the passed bytes length is larger than 4.
assert b.length >= 4;
return ((b[0] & 0xFF) << 24) + ((b[1] & 0xFF) << 16) + ((b[2] & 0xFF) << 8) + ((b[3] & 0xFF) << 0);
intbytesToInteger(byte[] b, int off)
bytes To Integer
assert b.length - off >= 4;
return ((b[off++] & 0xFF) << 24) + ((b[off++] & 0xFF) << 16) + ((b[off++] & 0xFF) << 8)
        + ((b[off] & 0xFF) << 0);
intbytesToInteger(byte[] bytes)
bytes To Integer
return (bytes[0] << 24) & 0xff000000 | (bytes[1] << 16) & 0x00ff0000 | (bytes[2] << 8) & 0x0000ff00
        | (bytes[3]) & 0x000000ff;
voidbytesToInts(byte[] a, int ao, int[] b, int bo, int len)
bytes To Ints
for (int i = 0; i < len; ++i)
    b[bo + i] = bytesToInt(a, ao + (i << 2));
int[]bytesToInts(byte[] bytes, int shift, int[] spec)
bytes To Ints
for (int i = 0; i < 4; i++) {
    spec[i] = 0;
    int index = 4 * i + shift;
    for (int j = 0; j < 4; j++) {
        spec[i] = (spec[i] << 8) + (bytes[index + j] & 0xff);
return spec;
...
int[]bytesToInts(byte[] data)
Convert an array of bytes into a new array of integers.
int[] a = new int[data.length / 4];
for (int i = 0; i < a.length; i++) {
    a[i] = (data[i * 4] & 0xFF) | ((data[i * 4 + 1] & 0xFF) << 8) | ((data[i * 4 + 2] & 0xFF) << 16)
            | ((data[i * 4 + 3] & 0xFF) << 24);
return a;
int[][]bytesToInts(byte[][] bytes)
bytes To Ints
int[][] ints = new int[bytes.length][];
for (int a = 0; a < bytes.length; a++) {
    byte[] bs = bytes[a];
    int[] is = new int[bs.length];
    ints[a] = is;
    for (int i = 0; i < bs.length; i++) {
        is[i] = bs[i] & 0xff;
return ints;
intbyteToInt(byte b[])
byte To Int
int s = 0;
s = ((((b[0] & 0xff) << 8 | (b[1] & 0xff)) << 8) | (b[2] & 0xff)) << 8 | (b[3] & 0xff);
return s;
intbyteToInt(byte[] b)
byte To Int
int s = 0;
final int n256 = 256;
final int n2 = 2;
for (int i = 0; i < n2; i++) {
    s = s * n256;
    if (b[i] >= 0) {
        s = s + b[i];
    } else {
...