我需要将字节数组转换为短数组。我不知道为什么它不起作用!这是我的代码:
private short[] byte2short(byte[] buffer) {
int byteArrsize = buffer.length;
short[] shorts = new short [ byteArrsize/2];
for (int i = 0; i < byteArrsize; i++) {
short MSB = (short) buffer[2*i+1];
short LSB = (short) buffer[2*i];
shorts[i] = (short) (MSB << 8 | (255 & LSB));
}
return shorts;
}