Android Utililty Methods Byte Array to Short Convert

List of utility methods to do Byte Array to Short Convert

Description

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

Method

int[]bytesBE2ushorts(byte[] b)
bytes B 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] = bytesBE2ushort(b, i << 1);
return val;
...
short[]bytesLE2shorts(byte[] b)
bytes L Eshorts
if (b == null)
    return null;
if ((b.length & 0x1) != 0)
    throw new IllegalArgumentException("byte[" + b.length + "]");
short[] val = new short[b.length >> 1];
for (int i = 0; i < val.length; i++)
    val[i] = (short) bytesLE2sshort(b, i << 1);
return val;
...
intbytesLE2sshort(byte[] b, int off)
bytes L Esshort
return (b[off + 1] << 8) | (b[off] & 0xff);
int[]bytesLE2sshorts(byte[] b)
bytes L Esshorts
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] = bytesLE2sshort(b, i << 1);
return val;
...
intbytesLE2ushort(byte[] b, int off)
bytes L Eushort
return bytesLE2sshort(b, off) & 0xffff;
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;
...
shortbytesToShort(byte[] b)
bytes To Short
short s0 = (short) (b[0] & 0xff);
short s1 = (short) (b[1] & 0xff);
s1 <<= 8;
return (short) (s0 | s1);
shortbytesToShort(byte[] b)
bytes To Short
ByteBuffer buf = ByteBuffer.wrap(b, 0, 2);
buf.order(ByteOrder.LITTLE_ENDIAN);
return buf.getShort();
shortbytesToShort(byte[] bytes)
Converts a byte[] of unsigned bytes in big-endian order to a short.
short s = 0;
s |= (bytes[0] & 0xFF) << 8;
s |= (bytes[1] & 0xFF);
return s;
shortgetShort(byte[] b, int index)
get Short
return (short) (((b[index] << 8) | b[index + 1] & 0xff));