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

intBytesToInt(byte[] value)
Bytes To Int
int result = 0;
for (int i = 0; i < 4; i++) {
    int shift = (4 - 1 - i) * 8;
    result += (value[i] & 0x000000FF) << shift;
return result;
intbytesToInt(byte[] bytes)
bytes To Int
return bytes[3] & 0xFF | (bytes[2] & 0xFF) << 8
        | (bytes[1] & 0xFF) << 16 | (bytes[0] & 0xFF) << 24;
intbytesToInt(byte[] bytes)
bytes To Int
return bytes[3] & 0xFF | (bytes[2] & 0xFF) << 8
        | (bytes[1] & 0xFF) << 16 | (bytes[0] & 0xFF) << 24;
intbytesToInt(byte[] bytes, int offset)
bytes To Int
int value = 0;
for (int bi = 0; bi < 4; ++bi) {
    value |= (0x000000FF & (int) bytes[bi + offset]) << (bi * 8);
return value;
intswap32bitFromArray(byte[] value, int offset)
Reads a signed 32 bit integer from an array coming from a device.
int v = 0;
v |= ((int) value[offset]) & 0x000000FF;
v |= (((int) value[offset + 1]) & 0x000000FF) << 8;
v |= (((int) value[offset + 2]) & 0x000000FF) << 16;
v |= (((int) value[offset + 3]) & 0x000000FF) << 24;
return v;
voidswap32bitsToArray(int value, byte[] dest, int offset)
Swaps an unsigned value around, and puts the result in an array that can be sent to a device.
dest[offset] = (byte) (value & 0x000000FF);
dest[offset + 1] = (byte) ((value & 0x0000FF00) >> 8);
dest[offset + 2] = (byte) ((value & 0x00FF0000) >> 16);
dest[offset + 3] = (byte) ((value & 0xFF000000) >> 24);
intswapU16bitFromArray(byte[] value, int offset)
Reads an unsigned 16 bit integer from an array coming from a device, and returns it as an 'int'
int v = 0;
v |= ((int) value[offset]) & 0x000000FF;
v |= (((int) value[offset + 1]) & 0x000000FF) << 8;
return v;
inttoInt(byte[] in)
to Int
int out = 0;
for (int i = in.length - 1; i > 0; i--) {
    out |= in[i] & 0xff;
    out <<= 8;
out |= in[0] & 0xff;
return out;
intparseInt(byte[] b, int start, int end, int radix)
Convert the bytes within the specified range of the given byte array into a signed integer in the given radix .
if (b == null)
    throw new NumberFormatException("null");
int result = 0;
boolean negative = false;
int i = start;
int limit;
int multmin;
int digit;
...
intparseInt(byte[] b, int start, int end)
Convert the bytes within the specified range of the given byte array into a signed integer .
return parseInt(b, start, end, 10);