注意byte数组长度必须是2的倍数
public static short[] toShortArray(byte[] src) {
int count = src.length >> 1;
short[] dest = new short[count];
for (int i = 0; i < count; i++) {
dest[i] = (short) (src[i * 2] << 8 | src[2 * i + 1] & 0xff);
}
return dest;
}
public static byte[] toByteArray(short[] src) {
int count = src.length;
byte[] dest = new byte[count << 1];
for (int i = 0; i < count; i++) {
dest[i * 2] = (byte) (src[i] >> 8);
dest[i * 2 + 1] = (byte) (src[i] >> 0);
}
return dest;
}