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[] value)
bytes To Int
int iOutcome = 0;
byte bLoop;
for (int i = 0; i < value.length; i++) {
    bLoop = value[i];
    iOutcome += (bLoop & 0xFF) << (8 * i);
return iOutcome;
intbytesToInt(final byte[] arr)
Returns an int extracted from a Little-Endian byte array.
int v = 0;
for (int i = 0; i < 4; i++) {
    v |= (arr[i] & 0XFF) << i * 8;
return v;
intbytesToInt(final byte[] b)
bytes To Int
return b[3] & 0xFF | (b[2] & 0xFF) << 8 | (b[1] & 0xFF) << 16 | (b[0] & 0xFF) << 24;
intbytesToInt(final byte[] buf, final int offset)
bytes To Int
if (buf == null) {
    throw new NullPointerException("buf must not be null");
if (offset < 0) {
    throw new IndexOutOfBoundsException("negative offset:" + offset);
if (buf.length < offset + INT_BYTE_LENGTH) {
    throw new IndexOutOfBoundsException(
...
intbytesToInt(final byte[] bytes)
convert given byte array to integer
int result = 0;
if (bytes == null) {
    return 0;
for (int i = 0; i < bytes.length; i++) {
    int temp = (int) bytes[i];
    if (temp < 0) {
        temp = 0x100 + temp;
...
intbytesToInt(final byte[] bytes)
bytes To Int
assertNotNull("bytes", bytes);
if (bytes.length != 4)
    throw new IllegalArgumentException("bytes.length != 4");
return bytesToInt(bytes, 0);
intbytesToInt(final byte[] bytes, final int position, final int length, final int bitShiftStart, final int bitShitIncrement)
bytes To Int
if (length > 4)
    throw new IllegalArgumentException("The maximum capacity for an int is 32 bytes");
final int signum = bytes[position] < 0 ? -1 : 1;
final int positiveNum = (int) bytesToUInt(bytes, position, length, bitShiftStart, bitShitIncrement);
return signum * positiveNum;
intbytesToInt(int off, byte... arr)
bytes To Int
int n = 0;
for (int i = 0; i < 4; i++) {
    n |= (arr[i + off] & 0xFF) << 8 * i;
return n;
intbytesToInt16(byte highByte, byte lowByte)
Converts 2 bytes to a signed integer sample with 16bit range.
return (highByte << 8) | (lowByte & 0xFF);
intbytesToInt2(byte[] arr, int offset)
bytes To Int
int value;
value = (int) (((arr[offset] & 0xFF) << 24) | ((arr[offset + 1] & 0xFF) << 16)
        | ((arr[offset + 2] & 0xFF) << 8) | (arr[offset + 3] & 0xFF));
return value;