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

intbytesToInt(byte bytes[], int start)
bytes To Int
int value = ((bytes[start + 3] & 255)) | ((bytes[start + 2] & 255) << 8) | ((bytes[start + 1] & 255) << 16)
        | ((bytes[start] & 255) << 24);
return value;
intbytesToInt(byte low, byte high)
This method combines two bytes into an integer.
return ((int) low & 0xff) | (((int) high & 0xff) << 8);
intbytesToInt(byte[] array, int offset)
Extracts the big-endian integer starting at offset from array.
int highWord = ((array[offset] & 0xff) << 24) | ((array[offset + 1] & 0xff) << 16);
int lowWord = ((array[offset + 2] & 0xff) << 8) | (array[offset + 3] & 0xff);
return highWord | lowWord;
intbytesToInt(byte[] array, int offset)
Unmarshal a byte array to an integer.
int b1, b2, b3, b4;
b1 = (array[offset++] << 24) & 0xFF000000;
b2 = (array[offset++] << 16) & 0x00FF0000;
b3 = (array[offset++] << 8) & 0x0000FF00;
b4 = (array[offset++] << 0) & 0x000000FF;
return (b1 | b2 | b3 | b4);
intbytesToInt(byte[] b)
Converts a byte array to a representative int
return ((b[0] << 24) & 0xff000000) | ((b[1] << 16) & 0xff0000) | ((b[2] << 8) & 0xff00) | (b[3] & 0xff);
intbytesToInt(byte[] b)
bytes To Int
int mask = 0xff;
int temp = 0;
int n = 0;
for (int i = 0; i < b.length; i++) {
    n <<= 8;
    temp = b[i] & mask;
    n |= temp;
return n;
intbytesToInt(byte[] b)
bytes To Int
return bytesToInt(b[0], b[1], b[2], b[3]);
intbytesToInt(byte[] b)
bytes To Int
int i = (b[0] << 24) & 0xFF000000;
i |= (b[1] << 16) & 0xFF0000;
i |= (b[2] << 8) & 0xFF00;
i |= b[3] & 0xFF;
return i;
intbytesToInt(byte[] b)
Converts a byte array into an integer.
if (b.length < 4) {
    throw new IllegalArgumentException("The length of the byte array should be >= 4");
return ((b[3] & BYTESIZE)) + ((b[2] & BYTESIZE) << 8) + ((b[1] & BYTESIZE) << 16)
        + ((b[0] & BYTESIZE) << 24);
intbytesToInt(byte[] b, int i)
bytes To Int
return ((((b[i + 3]) & 0xff) << 0) | (((b[i + 2]) & 0xff) << 8) | (((b[i + 1]) & 0xff) << 16)
        | (((b[i + 0]) & 0xff) << 24));