Android Utililty Methods Byte Array to Int Convert

List of utility methods to do Byte Array to Int Convert

Description

The list of methods to do Byte Array to Int Convert are organized into topic(s).

Method

inttoInteger(byte[] input, int offset)
to Integer
assert offset + 4 <= input.length : "Invalid length "
        + input.length;
return ((input[offset++] & 0xff) << 24)
        | ((input[offset++] & 0xff) << 16)
        | ((input[offset++] & 0xff) << 8)
        | ((input[offset++] & 0xff));
intreadInt(byte[] buff, int pos)
read Int
return (buff[pos++] << 24) + ((buff[pos++] & 0xff) << 16)
        + ((buff[pos++] & 0xff) << 8) + (buff[pos] & 0xff);
intgetShort(byte[] data)
get Short
return (int) ((data[0] << 8) | data[1] & 0xFF);
intgetUnsignedSafe(byte[] buffer, int pos)
Convert byte from byte buffer to unsigned integer.
if (null == buffer || pos >= buffer.length || pos < 0) {
    return 0;
int res = toUnsignedInteger(buffer[pos]);
return res;
inttoUInt16(byte[] bytes, int start)
to U Int
return (bytes[start] & 0xff) + ((bytes[start + 1] & 0xff) << 8);
voidintToOctet(byte[] buf, int i)
int To Octet
buf[0] = (byte) (i >>> 24);
buf[1] = (byte) (i >>> 16);
buf[2] = (byte) (i >>> 8);
buf[3] = (byte) i;
intreadInt(byte[] byteArray, int offset)
read Int
int i = 0;
for (int j = 0; j < 4; j++) {
    int shift = 24 - j * 8;
    i += (byteArray[offset + j] & 0xFF) << shift;
return i;
voidwriteInt(byte[] byteArray, int offset, int i)
write Int
for (int j = 0; j < 4; j++) {
    int shift = 24 - j * 8;
    byteArray[offset + j] = (byte) (i >>> shift);