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

voidgetInts(int[] toInts, byte[] fromBytes)
get Ints
for (int intInd = 0; intInd < toInts.length; ++intInd) {
    final int fromInt = getInt(intInd * 4, fromBytes);
    int toInt = fromInt;
    toInts[intInd] = toInt;
voidgetInts(int[] toInts, byte[] fromBytes, int fromOffset)
get Ints
for (int intInd = 0; intInd < toInts.length; ++intInd) {
    final int fromInt = getInt(fromOffset + (intInd * INT_SIZE),
            fromBytes);
    int toInt = fromInt;
    toInts[intInd] = toInt;
intgetUIntByByte(byte data)
new byte[] { 8, 4, 2, 1 } => 00000001 00000010 00000100 00001000
return data & 0xFF;
longgetUIntByByteArray(byte[] data)
new byte[] { 8, 4, 2, 1 } => 00000001 00000010 00000100 00001000
return getUIntByByteArray(data, true);
longgetUIntByByteArray(byte[] data, boolean isLH)
get U Int By Byte Array
long result = 0;
for (int i = 0; i < data.length; i++) {
    byte b = data[i];
    int t = getUIntByByte(b);
    result += t << ((isLH ? i : data.length - i - 1) * 8);
return result;
inttoInt(byte[] src)
to Int
return toInt(src, 0);
inttoInt(byte[] src, int srcPos)
to Int
int dword = 0;
for (int i = 0; i < 4; i++) {
    dword = (dword << 8) + (src[i + srcPos] & 0xFF);
return dword;
inttoIntFromTwoBytes(byte[] b, int pos)
to Int From Two Bytes
int ret = 0;
ret |= (b[pos] & 0xFF);
ret |= (b[pos + 1] & 0xFF) << 8;
return (int) ret;
inttoInteger(byte[] b, int pos)
to Integer
int ret = 0;
for (int i = 0; i < 4; i++) {
    ret |= (b[i + pos] & 0xFF) << (8 * i);
return ret;
inttoInteger(byte[] b, int pos, int width)
to Integer
int retVal = Integer.MAX_VALUE;
switch (width) {
case 1:
    retVal = b[pos];
    if (retVal < 0) {
        retVal &= 0x000000FF;
    break;
...