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)
bytes To Int
return (0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)) | (0xff0000 & (bytes[2] << 16))
        | (0xff000000 & (bytes[3] << 24));
intbytesToInt(byte[] bytes)
bytes To Int
final byte[] tmp = new byte[4];
for (int i = bytes.length; i > 0; i--) {
    tmp[3 - i + 1] = bytes[bytes.length - i];
return (tmp[0] << 24) + ((tmp[1] & 0xFF) << 16) + ((tmp[2] & 0xFF) << 8) + (tmp[3] & 0xFF);
intbytesToInt(byte[] bytes, int bitOffset, int bitCount)
bytes To Int
int bitReadIndex = bitOffset;
int byteReadIndex = bitReadIndex / 8;
int bitWriteCount = 0;
int result = 0;
while (bitWriteCount < bitCount) {
    int value = (bytes[byteReadIndex] & 0xFF);
    int bitRelative = bitReadIndex - (8 * byteReadIndex);
    result = Integer.rotateLeft(result, 1) + (Integer.rotateRight(value, 7 - bitRelative) & 0x01);
...
intbytesToInt(byte[] bytes, int offset)
32 bit.
int result = 0x00000000;
int length;
if (bytes.length - offset < 4) 
    length = bytes.length - offset;
else
    length = 4;
int end = offset + length;
for (int i = 0; i < length; i++) {
...
intbytesToInt(byte[] bytes, int offset, int length)
bytes To Int
int value = 0;
for (int i = 0; i < length; i++) {
    value |= ((int) (bytes[offset + i] & 0xff) << (8 * i));
return value;
intbytesToInt(byte[] bytes, int start)
bytes To Int
int a = 0xff & bytes[start + 0];
int b = 0xff00 & (bytes[start + 1] << 8);
int c = 0xff0000 & (bytes[start + 2] << 16);
int d = 0xff000000 & (bytes[start + 3] << 24);
return a + b + c + d;
intbytesToInt(byte[] bytesSource)
bytes To Int
int num = 0;
num |= (0xFF & bytesSource[0]);
int i = 0;
while (i++ < bytesSource.length - 1) {
    num = (num << 8) | (0xFF & bytesSource[i]);
return num;
intbytesToInt(byte[] data)
bytes To Int
int value = (data[3] & 0xff);
value = value << 8;
value |= (data[2] & 0xff);
value <<= 8;
value |= (data[1] & 0xff);
value <<= 8;
value |= (data[0] & 0xff);
return value;
...
longbytesToInt(byte[] data)
bytes To Int
int offset = 0;
int a1 = data[offset + 3] & 0xFF;
int a2 = data[offset + 2] & 0xFF;
int a3 = data[offset + 1] & 0xFF;
int a4 = data[offset + 0] & 0xFF;
return (a1) + (a2 << 8) + (a3 << 16) + (a4 << 24);
intbytesToInt(byte[] data)
bytes To Int
return bytesToInt(data, 0);