List of utility methods to do Byte Array to Short
short | bytes2short(byte[] src) bytesshort return bytes2short(src, 0); |
short | bytesToShort(byte A, byte B) bytes To Short short i = (short) (B & MASK_TO_BYTE); i |= ((A & MASK_TO_BYTE) << 8); return i; |
short | bytesToShort(byte a, byte b, boolean swapBytes) Concatenate two bytes to a short integer value. if (swapBytes) { return (short) ((a & 0xff) + (b & 0xff) << 8); } else { return (short) (((a & 0xff) << 8) + (b & 0xff)); |
short | bytesToShort(byte b1, byte b2) bytes To Short return (short) bytesToUshort(b1, b2); |
short | bytesToShort(byte byte1, byte byte2) bytes To Short return (short) (0xffff & ((0xff & byte1) | ((0xff & byte2) << 8))); |
short | bytesToShort(byte hiByte, byte loByte) Reconstructs a short from its hi and low bytes. int result = (0x000000FF & hiByte); result = result << 8; result |= (0x000000FF & loByte); return (short) result; |
short | bytesToShort(byte[] buf) bytes To Short return (short) (((0xff & buf[0]) << 8) | (0xff & buf[1])); |
short | bytesToShort(byte[] buffer, int index) This function converts the bytes in a byte array at the specified index to its corresponding short value. int length = 2; short integer = 0; for (int i = 0; i < length; i++) { integer |= ((buffer[index + length - i - 1] & 0xFF) << (i * 8)); return integer; |
short | bytesToShort(byte[] bytes) 16 bit. return bytesToShort(bytes, 0);
|
short | bytesToShort(byte[] bytes) Convert a byte array into a short takes the 4 smallest bits of every byte, you can give an array with less or more than 4 bytes put you have a risk of overflow or an unexpected result short num = 0; for (int i = 0; i < bytes.length; i++) { num += (bytes[i] & 0xF) << (i * 4); return num; |