I have a byte array where the data in the array is actually short data. The bytes are ordered in little endian:
3, 1, -48, 0, -15, 0, 36, 1
Which when conver
/* Try this: */
public static short byteArrayToShortLE(final byte[] b, final int offset)
{
short value = 0;
for (int i = 0; i < 2; i++)
{
value |= (b[i + offset] & 0x000000FF) << (i * 8);
}
return value;
}
/* if you prefer... */
public static int byteArrayToIntLE(final byte[] b, final int offset)
{
int value = 0;
for (int i = 0; i < 4; i++)
{
value |= ((int)b[i + offset] & 0x000000FF) << (i * 8);
}
return value;
}