Java Utililty Methods Byte Array to Short

List of utility methods to do Byte Array to Short

Description

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

Method

shortarr2short(byte[] arr)
arrshort
int i = 0;
i |= arr[0] & 0xFF;
i <<= 8;
i |= arr[1] & 0xFF;
return (short) i;
shortbufferToShort(byte[] ioBuffer)
buffer To Short
return (short) ((ioBuffer[0] << 8) | (ioBuffer[1] & 255));
short[]byte2short(byte[] ba)
byteshort
int length = ba.length;
short[] sa = new short[length / 2];
for (int i = 0, j = 0; j < length / 2;) {
    sa[j++] = (short) (((ba[i++] & 0xFF) << 8) | ((ba[i++] & 0xFF)));
return (sa);
shortbyte2short(byte[] data)
byteshort
if (data != null && data.length == 2) {
    return (short) (((data[1] & 0xff) << 8) + (data[0] & 0xff));
return 0;
shortbyte2short(byte[] value, int offset)
byteshort
long result = (((long) (value[0 + offset]) & 0xFF) << 8) | ((long) (value[1 + offset]) & 0xFF);
return (short) (result & 0xFFFFL);
shortbyte2Short(int loc, byte b[])
byte Short
short m1, m2;
m1 = (short) (b[loc]);
if (m1 < 0)
    m1 = (short) (256 + m1);
m2 = (short) (b[loc + 1]);
if (m2 < 0)
    m2 = (short) (256 + m2);
m2 = (short) (256 * m2 + m1);
...
shortbytes2short(byte[] b)
to short.
return bytes2short(b, 0);
shortbytes2Short(byte[] bytes)
bytes Short
short val = 0;
for (int i = 0; i < 2; i++) {
    val |= (0xFF & (short) bytes[i]) << (8 * i);
return val;
shortbytes2short(byte[] bytes, int offset, boolean bigEndian)
bytesshort
short val = 0;
if (bigEndian) {
    val += (bytes[offset + 0] & 0xff) << 8;
    val += (bytes[offset + 1] & 0xff);
} else {
    val += (bytes[offset + 1] & 0xff) << 8;
    val += (bytes[offset + 0] & 0xff);
return val;
shortbytes2Short(byte[] input)
bytes Short
return (short) ((input[0] & 0xFF) | ((input[1] << 8) & 0xFF00));