private static byte[] shortToByteArray(short s)
{
byte[] shortBuf = new byte[2];
for(int i=0;i<2;i++) {
int offset = (shortBuf.length - 1 -i)*8;
shortBuf[i] = (byte)((s>>>offset)&0xff);
}
return shortBuf;
}
byte[] shortBuf = new byte[2];
for(int i=0;i<2;i++) {
int offset = (shortBuf.length - 1 -i)*8;
shortBuf[i] = (byte)((s>>>offset)&0xff);
}
return shortBuf;
}
本文介绍了一个将16位短整型数据转换为两个字节的方法。通过循环迭代,该方法实现了高位到低位的数据转换,并返回包含两个字节的数组。
2585

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



