java 数据转换

byte[]转 short[]
byte[] mBuffer = new mBuffer[size];
int count = mBuffer.length >> 1;
short[] dest = new short[count];
for (int i = 0; i < count; i++) {
dest[i] = (short) ((mBuffer[i * 2] & 0xff) | ((mBuffer[2 * i + 1] & 0xff) << 8));
}

short[]转byte[]

byte[] dest = new byte[count << 1];
for (int i = 0; i < count; i++) {
  dest[i * 2] = (byte) (mBuffer[i] >> 8);
  dest[i * 2 + 1] = (byte) (mBuffer[i] >> 0);
}
 

posted on 2018-01-26 13:48  回忆那么伤丶  阅读(98)  评论(0编辑  收藏  举报

导航