int
//整數到字節數組的轉換
public static byte[] intToByte(int number) {
int temp = number;
byte[] b=new byte[
for (int i=b
b[i] = new Integer(temp&
temp = temp >>
}
return b;
}
//字節數組到整數的轉換
public static int byteToInt(byte[] b) {
int s =
for (int i =
if (b[i] >=
s = s + b[i];
else
s = s +
s = s *
}
if (b[
s = s + b[
else
s = s +
return s;
}
//字符到字節轉換
public static byte[] charToByte(char ch){
int temp=(int)ch;
byte[] b=new byte[
for (int i=b
b[i] = new Integer(temp&
temp = temp >>
}
return b;
}
//字節到字符轉換
public static char byteToChar(byte[] b){
int s=
if(b[
s+=b[
else
s+=
s*=
if(b[
s+=b[
else
s+=
char ch=(char)s;
return ch;
}
//浮點到字節轉換
public static byte[] doubleToByte(double d){
byte[] b=new byte[
long l=Double
for(int i=
b[i]=new Long(l)
l=l>>
}
return b;
}
//字節到浮點轉換
public static double byteToDouble(byte[] b){
long l;
l=b[
l&=
l|=((long)b[
l&=
l|=((long)b[
l&=
l|=((long)b[
l&=
l|=((long)b[
l&=
l|=((long)b[
l&=
l|=((long)b[
l|=((long)b[7]<<56);
return Double.longBitsToDouble(l);
}
--
From:http://tw.wingwit.com/Article/program/Java/JSP/201311/19749.html