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

shortbytesToShort(final byte[] aBuffer, final int aPos)
bytes To Short
if (aBuffer.length - aPos < LEN_OF_SHORT) {
    throw new IllegalArgumentException("Byte array should contain at least 2 bytes");
short l = 0;
for (int i = 0; i < LEN_OF_SHORT; i++) {
    l += (unsignedByteToLong(aBuffer[aPos + 1 - i]) << (8 * i));
return l;
...
shortbytesToShort(final byte[] data)
bytes To Short
short value = (short) (data[1] & 0xff);
value <<= 8;
value |= data[0] & 0xff;
return value;
shortbytesToShort16(byte highByte, byte lowByte)
bytes To Short
return (short) ((highByte << 8) | (lowByte & 0xFF));
intbytesToShortBE(byte[] bytes, int off)
bytes To Short BE
return (bytes[off] << 8) + (bytes[off + 1] & 255);
intbytesToShortLittleEndian(final byte[] vals, final int from)
bytes into single short
return ((vals[from + 1] & 0xFF) << 8) + (vals[from] & 0xFF);
short[]bytesToShorts(byte byteBuffer[])
bytes To Shorts
int len = byteBuffer.length / 2;
short[] output = new short[len];
int j = 0;
for (int i = 0; i < len; i++) {
    output[i] = (short) (byteBuffer[j++] << 8);
    output[i] |= (byteBuffer[j++] & 0xff);
return output;
...
short[]bytesToShorts(byte[] byteData)
Convert a byte array to short array.
short[] shortData = new short[byteData.length];
for (int i = 0; i < byteData.length; i++) {
    shortData[i] = (short) byteData[i];
return shortData;
voidbytesToShorts(byte[] src, int srcPos, short[] dest, int destPos, int length, boolean bigEndian)
bytes To Shorts
if (bigEndian)
    bytesToShortsBE(src, srcPos, dest, destPos, length);
else
    bytesToShortsLE(src, srcPos, dest, destPos, length);
shortbyteToShort(byte[] b)
byte To Short
short s = 0;
short s0 = (short) (b[0] & 0xff);
short s1 = (short) (b[1] & 0xff);
s1 <<= 8;
s = (short) (s0 | s1);
return s;
short[]byteToShort(byte[] byteData, boolean writeLittleEndian)
Function converts a byte array to a short array.
short[] data = new short[byteData.length / 2];
int size = data.length;
byte lb, hb;
if (writeLittleEndian) {
    for (int i = 0; i < size; i++) {
        lb = byteData[i * 2];
        hb = byteData[i * 2 + 1];
        data[i] = (short) (((short) hb << 8) | lb & 0xff);
...