List of utility methods to do Byte Array to Short Convert
short | bytesToShort(byte[] b) bytes To Short short s0 = (short) (b[0] & 0xff); short s1 = (short) (b[1] & 0xff); s1 <<= 8; return (short) (s0 | s1); |
short | bytesToShort(byte[] b) bytes To Short short s0 = (short) (b[0] & 0xff); short s1 = (short) (b[1] & 0xff); s1 <<= 8; return (short) (s0 | s1); |
short | toShort(byte[] in) to Short short out = 0; for (int i = in.length - 1; i > 0; i--) { out |= in[i] & 0xff; out <<= 8; out |= in[0] & 0xff; return out; |
short | byte2Short(byte bin) byte Short return (short) (bin & 0xFF); |
int | byteArray2Short(byte[] b) byte Array Short return (b[0] << 8) + (b[1] & 0xFF);
|
short | byteArrayToShort(byte[] b, int offset) byte Array To Short short value = 0; for (int i = 0; i < 2; i++) { int shift = (2 - 1 - i) * 8; value += (b[i + offset] & 0x000000FF) << shift; return value; |
short[] | bytesBE2shorts(byte[] b) bytes B Eshorts if (b == null) return null; if ((b.length & 0x1) != 0) throw new IllegalArgumentException("byte[" + b.length + "]"); short[] val = new short[b.length >> 1]; for (int i = 0; i < val.length; i++) val[i] = (short) bytesBE2sshort(b, i << 1); return val; ... |
int | bytesBE2sshort(byte[] b, int off) bytes B Esshort return (b[off] << 8) | (b[off + 1] & 0xff);
|
int[] | bytesBE2sshorts(byte[] b) bytes B Esshorts if (b == null) return null; if ((b.length & 0x1) != 0) throw new IllegalArgumentException("byte[" + b.length + "]"); int[] val = new int[b.length >> 1]; for (int i = 0; i < val.length; i++) val[i] = bytesBE2sshort(b, i << 1); return val; ... |
int | bytesBE2ushort(byte[] b, int off) bytes B Eushort return bytesBE2sshort(b, off) & 0xffff;
|