关于jav:short数组转发byte数组

62次阅读

共计 350 个字符,预计需要花费 1 分钟才能阅读完成。

short 数组转发 byte 数组并可实现位置换高位

byte[] tobytes(short[] shorts, boolean bigendian) {
    int n = 0;
    byte[] bytes = new byte[2*shorts.length];
 
    for (n=0; n < shorts.length; n++) {byte lsb = shorts[n] & 0xff;
        byte msb = (shorts[n] >> 8) & 0xff;
        if (bigendian) {bytes[2*n]   = msb;
            bytes[2*n+1] = lsb;
        } else {bytes[2*n]   = lsb;
            bytes[2*n+1] = msb;
        }
    }
    return bytes;
}

正文完
 0