java中long,int,short与byte数组之间的转换
来源:互联网 发布:美发软件那个好 编辑:程序博客网 时间:2024/05/16 13:00
//long类型转成byte数组
publicstaticbyte[] longToByte(long number){
long temp = number;
byte[] b=newbyte[8];
for(int i=0; i< b.length; i++){
b[i]=newLong(temp&0xff).byteValue();//
将最低位保存在最低位
temp = temp >>8;// 向右移8位
}
return b;
}
//byte数组转成long
publicstaticlong byteToLong(byte[] b){
long s =0;
long s0 = b[0]&0xff;// 最低位
long s1 = b[1]&0xff;
long s2 = b[2]&0xff;
long s3 = b[3]&0xff;
long s4 = b[4]&0xff;// 最低位
long s5 = b[5]&0xff;
long s6 = b[6]&0xff;
long s7 = b[7]&0xff;
// s0不变
s1 <<=8;
s2 <<=16;
s3 <<=24;
s4 <<=8*4;
s5 <<=8*5;
s6 <<=8*6;
s7 <<=8*7;
s = s0 | s1| s2 | s3| s4 | s5| s6 | s7;
return s;
}
/**
* 注释:int到字节数组的转换!
*
* @param number
* @return
*/
publicstaticbyte[] intToByte(int number){
int temp = number;
byte[] b=newbyte[4];
for(int i=0; i< b.length; i++){
b[i]=newInteger(temp&0xff).byteValue();//
将最低位保存在最低位
temp = temp >>8;// 向右移8位
}
return b;
}
/**
* 注释:字节数组到int的转换!
*
* @param b
* @return
*/
publicstaticint byteToInt(byte[] b){
int s =0;
int s0 = b[0]&0xff;// 最低位
int s1 = b[1]&0xff;
int s2 = b[2]&0xff;
int s3 = b[3]&0xff;
s3 <<=24;
s2 <<=16;
s1 <<=8;
s = s0 | s1| s2 | s3;
return s;
}
/**
* 注释:short到字节数组的转换!
*
* @param s
* @return
*/
publicstaticbyte[] shortToByte(short number){
int temp = number;
byte[] b=newbyte[2];
for(int i=0; i< b.length; i++){
b[i]=newInteger(temp&0xff).byteValue();//
将最低位保存在最低位
temp = temp >>8;// 向右移8位
}
return b;
}
/**
* 注释:字节数组到short的转换!
*
* @param b
* @return
*/
publicstaticshort byteToShort(byte[] b){
short s =0;
short s0 =(short)(b[0]&0xff);// 最低位
short s1 =(short)(b[1]&0xff);
s1 <<=8;
s =(short)(s0| s1);
return s;
}
publicstaticbyte[] longToByte(long number){
long temp = number;
byte[] b=newbyte[8];
for(int i=0; i< b.length; i++){
b[i]=newLong(temp&0xff).byteValue();//
将最低位保存在最低位
temp = temp >>8;// 向右移8位
}
return b;
}
//byte数组转成long
publicstaticlong byteToLong(byte[] b){
long s =0;
long s0 = b[0]&0xff;// 最低位
long s1 = b[1]&0xff;
long s2 = b[2]&0xff;
long s3 = b[3]&0xff;
long s4 = b[4]&0xff;// 最低位
long s5 = b[5]&0xff;
long s6 = b[6]&0xff;
long s7 = b[7]&0xff;
// s0不变
s1 <<=8;
s2 <<=16;
s3 <<=24;
s4 <<=8*4;
s5 <<=8*5;
s6 <<=8*6;
s7 <<=8*7;
s = s0 | s1| s2 | s3| s4 | s5| s6 | s7;
return s;
}
/**
* 注释:int到字节数组的转换!
*
* @param number
* @return
*/
publicstaticbyte[] intToByte(int number){
int temp = number;
byte[] b=newbyte[4];
for(int i=0; i< b.length; i++){
b[i]=newInteger(temp&0xff).byteValue();//
将最低位保存在最低位
temp = temp >>8;// 向右移8位
}
return b;
}
/**
* 注释:字节数组到int的转换!
*
* @param b
* @return
*/
publicstaticint byteToInt(byte[] b){
int s =0;
int s0 = b[0]&0xff;// 最低位
int s1 = b[1]&0xff;
int s2 = b[2]&0xff;
int s3 = b[3]&0xff;
s3 <<=24;
s2 <<=16;
s1 <<=8;
s = s0 | s1| s2 | s3;
return s;
}
/**
* 注释:short到字节数组的转换!
*
* @param s
* @return
*/
publicstaticbyte[] shortToByte(short number){
int temp = number;
byte[] b=newbyte[2];
for(int i=0; i< b.length; i++){
b[i]=newInteger(temp&0xff).byteValue();//
将最低位保存在最低位
temp = temp >>8;// 向右移8位
}
return b;
}
/**
* 注释:字节数组到short的转换!
*
* @param b
* @return
*/
publicstaticshort byteToShort(byte[] b){
short s =0;
short s0 =(short)(b[0]&0xff);// 最低位
short s1 =(short)(b[1]&0xff);
s1 <<=8;
s =(short)(s0| s1);
return s;
}
- java中long,int,short与byte数组之间的转换
- java中long,int,short与byte数组之间的转换
- java中byte数组与int,long,short,float,char之间的转换
- java中byte数组与int,long,short,float,char之间的转换
- java中long,int,short与byte数组之间的转换
- Java中byte数组与short,int,char,long,float,double之间的转换
- java中long,int,short与byte数组之间的转换
- Java中byte数组与short,int,char,long,float,double之间的转换
- short,int,long与byte数组之间的转换
- Java异常处理及异常机制介绍 && long,int,short与byte数组之间的转换
- java中byte数组和int,long,short之间的转换
- Java 语言中 short 与 byte[]之间的转换,int、long 类似。
- java中long,int,short与byte数组之间的转
- java byte数组与int,long,short,byte转换
- java byte数组与int,long,short,byte转换
- java中byte数组与int,long,short间的转换
- java中byte数组与int,long,short间的转换 .
- java中byte数组与int,long,short间的转换
- OpenR2 呼叫流程
- APC&INV different about items
- 网络端口大全
- eclipse遇到An error has occurred. See the log file
- 子线程阻塞的一个解决方案
- java中long,int,short与byte数组之间的转换
- LVS Tutorial
- ok6410增加工作队列的platform按键驱动程序
- 用CoreText 实现显示可点击 的URL
- vlc的应用之一:在命令行下的使用
- The absolute uri: http://java.sun.com/jsp/jstl/core cannot be resolved in either web.xml or the jar
- windows bat .
- Java基本类型 和所占位数
- web.xml中load-on-startup标签的含义