byte[]转换成short[]
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;
}
short[]转换成byte[]
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;
}
博客主要介绍了信息技术领域中byte[]数组和short[]数组的相互转换操作,这在数据处理等场景中较为常见。
1万+

被折叠的 条评论
为什么被折叠?



