org.neodatis.odb.core.io.ByteArrayConverter
这个类的作用是 :Converts array of bytes into native objects and native objects into array of bytes
public class ByteArrayConverter {
……
/**
* bit 二进制位(或称比特) byte 字节 1Byte=8bit kilobyte(kb) 千字节 megabyte(mb) 兆字节
* 1Mb=1024KB=1024*1024Byte gigabyte(gb) 吉字节 terabyte(tb) 太字节 PetaByte (PB)
* ExaByte (EB) ZetaByte (ZB) YottaByte (YB) NonaByte (NB) DoggaByte (DB)
*
* byte 字节型 1个字节 -128-127 short 短整型 2个字节 -2的15次幂-2的15次幂-1 int 整型 4个字节
* -2的31次幂-2的31次幂-1 long 长整型 8个字节 -2的63次幂~2的63次幂-1
*
* @param s
* @return 先低后高
*/
public static byte[] shortToByteArray(short s) {
byte b[] = new byte[2];
int i,shift;
for (i = 0,shift = 8; i < 2; i++,shift -= 8) {
b[i] = (byte) (0xFF & (s >> shift));//&0000 0000 1111 1111 先取低位,后取高位
}
return b;
}
public static short byteArrayToShort(byte[] bytes) {
short result = 0;
for (int i = 0; i < 2; i++) {
result <<= 8; // left shift out the last byte
result |= bytes[i] & 0xFF; // OR in the new byte 将高低位附加在一起
}
bytes = null;
return result;
}
……
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。