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

intbytes2int(byte value1, byte value2)
Example, hex code: 05 01
return (byte2int(value1) + byte2int(value2) * 256);
intbytes2Int(byte... bytes)
bytes Int
int value = 0;
int shift = 0;
for (byte b : bytes) {
    value |= (0xff & b) << shift;
    shift += 8;
return value;
int[]bytes2int(byte[] ary)
bytesint
int intLen = ary.length / 4;
int[] aryInt = new int[intLen];
for (int i = 0; i < aryInt.length; i++) {
    byte[] tmp = new byte[4];
    for (int j = 0; j < tmp.length; j++) {
        tmp[j] = ary[i * 4 + j];
    aryInt[i] = _bytes2int(tmp);
...
intbytes2int(byte[] b)
bytesint
return bytes2int(b, 0);
intbytes2Int(byte[] b, int start, int len)
bytes Int
int sum = 0;
int end = start + len;
for (int i = start; i < end; i++) {
    int n = (int) b[i] & 0xff;
    n <<= (--len) * 8;
    sum = n + sum;
return sum;
...
intbytes2int(byte[] buf)
Cat 4 bytes to make an int.
return (buf[0] << 24) | ((buf[1] & 0xff) << 16) | ((buf[2] & 0xff) << 8) | (buf[3] & 0xff);
intbytes2int(byte[] bytes)
bytesint
int num = 0;
for (int i = 0; i < 4; i++) {
    num <<= 8;
    num |= (bytes[i] & 0xff);
return num;
intbytes2int(byte[] bytes)
bytes to int
int result = 0;
for (int i = 0; i < 4; i++) {
    result = (result << 8) - Byte.MIN_VALUE + (int) bytes[i];
return result;
intbytes2int(byte[] bytes)
Converts Byte Array into Integer value
if (bytes == null) {
    return 0;
switch (bytes.length) {
case 1:
    return bytes[0] & 0xFF;
case 2:
    return (bytes[0] & 0xFF) << 8 | bytes[1] & 0xFF;
...
intbytes2Int(byte[] bytes)
bytes Int
int result = 0;
for (int i = 0; i < 4; i++)
    result += bytes[i] << 8 * (4 - i - 1);
return result;