List of utility methods to do Byte Array Little Endian
int[] | bytesLE2ushorts(byte[] b) bytes L Eushorts if (b == null) return null; if ((b.length & 0x1) != 0) throw new IllegalArgumentException("byte[" + b.length + "]"); int[] val = new int[b.length >> 1]; for (int i = 0; i < val.length; i++) val[i] = bytesLE2ushort(b, i << 1); return val; ... |
float | BytesLEToFloat(final byte[] value) Bytes LE To Float return Float.intBitsToFloat(BytesLEToInt(value));
|
short | BytesLEToShort(final byte[] buf) Bytes LE To Short short val = 0x0; for (int i = 0; i < buf.length; i++) { val += ((short) buf[i] & 0xFF) << (8 * i); return val; |
float | bytesLittleToFloat(byte[] data, int start) bytes Little To Float int ret = 0; ret = 0x000000ff & data[start + 0]; ret |= (0x000000ff & data[start + 1]) << 8; ret |= (0x000000ff & data[start + 2]) << 16; ret |= (0x000000ff & data[start + 3]) << 24; return Float.intBitsToFloat(ret); |
long | bytesLittleToLong(byte[] data, int start) bytes Little To Long long ret = 0;
ret = 0x00000000000000ffL & data[start++];
ret |= (0x00000000000000ffL & data[start++]) << 8;
ret |= (0x00000000000000ffL & data[start++]) << 16;
ret |= (0x00000000000000ffL & data[start++]) << 24;
ret |= (0x00000000000000ffL & data[start++]) << 32;
ret |= (0x00000000000000ffL & data[start++]) << 40;
ret |= (0x00000000000000ffL & data[start++]) << 48;
...
|
short | bytesLittleToShort(byte[] data, int start) bytes Little To Short short ret = 0; ret = (short) (data[start + 0] & 0x00ff); ret |= (0x00ff & data[start + 1]) << 8; return ret; |