List of utility methods to do Byte Array to Int Convert
int[] | toInts(byte... bytes) to Ints int[] ints = new int[bytes.length]; for (int i = 0; i < ints.length; i++) { ints[i] = toInt(bytes[i]); return ints; |
int | byteArrayToInt(byte[] b) byte Array To Int return b[3] & 0xFF | (b[2] & 0xFF) << 8 | (b[1] & 0xFF) << 16
| (b[0] & 0xFF) << 24;
|
int | bytes2int(byte[] data) bytesint int val = 0; val |= data[0] & 0x000000FF; val |= (data[1] << 8) & 0x0000FF00; val |= (data[2] << 16) & 0x00FF0000; val |= (data[3] << 24) & 0xFF000000; return val; |
int | byte2int(byte[] b) byteint return (0xFF & b[0]) << 24 | (0xFF & b[1]) << 16
| (0xFF & b[2]) << 8 | (0xFF & b[3]) << 0;
|
int | byteArray2Int(byte[] bs) byte Array Int if (bs.length != 4) throw new IllegalArgumentException(); int res = 0; res |= (bs[0] & BYTE_MASK) << 24; res |= (bs[1] & BYTE_MASK) << 16; res |= (bs[2] & BYTE_MASK) << 8; res |= (bs[3] & BYTE_MASK); return res; ... |
int | byteArrayToInt(byte[] b) byte Array To Int if (b.length != 4) return 0; if (b.length != 4) return 0; int i = 0; int i1 = ((b[0] >= 0) ? b[0] : (b[0] + 256)) << 24; i = i + i1; int i2 = ((b[1] >= 0) ? b[1] : (b[1] + 256)) << 16; ... |
int[] | toIntegerArray(byte[] input, int offset, int len) to Integer Array 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; |
void | toIntegerArray(byte[] input, int offset, int len, int[] output, int outputOffset) to Integer Array 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; |
int | toInt(byte[] bytes) to Int int result = 0; int base = 1; for (int i = bytes.length - 1; i >= 0; i--) { result = result + (toInt(bytes[i]) * base); base = base * 256; return result; |
int | toInteger(byte[] input) to Integer return toInteger(input, 0);
|