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

shortgetShort(byte[] b, int index)
get Short
return (short) (((b[index + 1] << 8) | b[index + 0] & 0xff));
shortgetShort(byte[] buf, boolean bigEndian)
Convert byte sequence into java short from first 2 bytes
return getShort(buf, 0, bigEndian);
shortgetShort(byte[] buf, int pos, boolean bigEndian)
Convert byte sequence into java short.
if (bigEndian) {
    return (short) ((buf[pos] << 8) | (buf[pos + 1] & 0xff));
} else {
    return (short) ((buf[pos + 1] << 8) | (buf[pos] & 0xff));
shortgetShort(byte[] bytes)
get Short
return (short) ((0xff & bytes[0]) | (0xff00 & (bytes[1] << 8)));
shorttoShort(byte[] b, int pos)
to Short
short ret = 0;
ret |= (b[pos] & 0xFF);
ret |= (b[pos + 1] & 0xFF) << 8;
return ret;
shorttoShort(byte[] data)
to Short
return byteArrayToShort(data, 0);
shorttoShort(byte[] data)
to Short
if (data == null || data.length != 2)
    return 0x0;
return (short) ((0xff & data[0]) << 8 | (0xff & data[1]) << 0);
shortmakeShort(byte b1, byte b0)
make Short
return (short) ((b1 << 8) | (b0 & 0xff));
shortbytes2short(byte[] data)
bytesshort
short val = 0;
val |= data[0] & 0x00FF;
val |= data[1] << 8;
return val;
StringByteToString(byte[] byteArray)
Byte To String
if (byteArray == null) {
    return null;
try {
    String result = new String(byteArray, "ASCII");
    result = String.copyValueOf(result.toCharArray(), 0,
            byteArray.length);
    return result;
...