List of utility methods to do Byte Array to Short
short | bytesToShort(byte[] bytes) Converts an array of bytes into a short Byte order: big endian return (short) ((((bytes[0] & BYTESIZE) << 8)) + (bytes[1] & BYTESIZE)); |
short | bytesToShort(byte[] bytes, boolean netOrder) bytes To Short if (bytes == null) { return 0; return (netOrder ? (short) ((bytes[0] & 0xFF << 8) | (bytes[1] & 0xFF)) : (short) ((bytes[1] & 0xFF << 8) | (bytes[0] & 0xFF))); |
short | bytesToShort(byte[] bytes, int off) Constructs short from byte array. assert bytes != null; int bytesCnt = Short.SIZE >> 3; if (off + bytesCnt > bytes.length) bytesCnt = bytes.length - off; short res = 0; for (int i = 0; i < bytesCnt; i++) { int shift = bytesCnt - i - 1 << 3; res |= (0xffL & bytes[off++]) << shift; ... |
short | bytesToShort(byte[] bytes, int off, boolean bigEndian) bytes To Short byte b1 = bytes[off], b2 = bytes[off + 1]; if (!bigEndian) { byte tmp = b1; b1 = b2; b2 = tmp; return (short) (((b1 & 0xFF) << 8) | (b2 & 0xFF)); |
short | bytesToShort(byte[] bytes, int off, int len, boolean little) bytes To Short if (bytes.length - off < len) len = bytes.length - off; short total = 0; for (int i = 0, ndx = off; i < len; i++, ndx++) { total |= (bytes[ndx] < 0 ? 256 + bytes[ndx] : (int) bytes[ndx]) << ((little ? i : len - i - 1) * 8); return total; |
short | bytesToShort(byte[] bytes, int offset) bytes To Short return bytesToShort(bytes[offset], bytes[offset + 1]);
|
short | bytesToShort(byte[] bytes, int start) bytes To Short short a = (short) (0xff & bytes[start + 0]); short b = (short) (0xff00 & (bytes[start + 1] << 8)); return (short) (a + b); |
short | bytesToShort(byte[] bytes, int startIndex) Given a byte array, restore it as a short return (short) (((int) bytes[startIndex] & 0xff) | (((int) bytes[startIndex + 1] & 0xff) << 8)); |
short | bytesToShort(byte[] shortBytes) bytes To Short byte[] data = new byte[2]; System.arraycopy(shortBytes, 0, data, 0, 2); return (short) (((data[0] << 8) | data[1] & 0xff)); |
short | bytesToShort(final byte byte0, final byte byte1) Read short value from two bytes. return (short) ((byte0 << BITS_8) + ((byte1 & BYTE_MAX) << BITS_0)); |