neodatis.odb 第二篇 一切都是比特
2008-05-03 17:22
381 查看
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;
}
……
这个类的作用是 :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;
}
……
相关文章推荐
- neodatis.odb 第五篇 保存
- neodatis.odb 第三篇 保存对象到文件的过程
- 一个neodatis-odb.jar包使用的例子
- neodatis.odb 第四篇 查询
- neodatis.odb 第六篇 更新和删除
- JAVA编程思想学习第二篇の一切都是对象
- neodatis.odb 第一篇 存储对象的偏移地址
- neodatis.odb 第七篇 学习odb日志1
- 一切都是Object.
- Java学习之第二章 一切都是对象
- 回忆,一切都是那么清晰_伤感日志
- 第四章 一切都是对象 4.1 两种思维方式
- Java编程思想 第4版 练习题 / 第2章 一切都是对象 / 练习3
- Java编程思想 第4版 练习题 / 第2章 一切都是对象 / 练习11
- 罗辑思维 140 认钱不认人(刚需是扯淡,一切都是稀缺,人生全是选择)——理性永远都是最珍贵的
- 程序化的思维与一通百通,一切语言都是纸老虎
- 第五章 开头。。。一切都是文件
- java编程思想学习笔记--第二章 一切都是对象
- 如果一切都是错误(未完待续)
- 【Java】《Java编程思想》笔记(含练习题答案代码)-第二章 一切都是对象