现在有这样的数组 E1 7A 14 AE 47 19 5E 40,经转换后为120.39500。
此数组是通过以下JAVA程序获得
/**
* double转化为Byte
*
* @param d
* @return
*/
public byte[] doubleToByte(double d) {
byte[] b = new byte[8];
long l = Double.doubleToLongBits(d);
for (int i = 0; i < 8; i++) {
b[i] = new Long(l).byteValue();
l = l >> 8;
}
return b;
}
现在想用C#反相将数据获取,请问如何获得呢
此数组是通过以下JAVA程序获得
/**
* double转化为Byte
*
* @param d
* @return
*/
public byte[] doubleToByte(double d) {
byte[] b = new byte[8];
long l = Double.doubleToLongBits(d);
for (int i = 0; i < 8; i++) {
b[i] = new Long(l).byteValue();
l = l >> 8;
}
return b;
}
现在想用C#反相将数据获取,请问如何获得呢
BitConverter.ToString(buffer)
BitConverter.ToString(byteArray) "40-5E-19-47-AE-14-7A-E1"
//字节到浮点转换
public static double byteToDouble(byte[] b){
long l;
l=b[0];
l&=0xff;
l|=((long)b[1]<<8);
l&=0xffff;
l|=((long)b[2]<<16);
l&=0xffffff;
l|=((long)b[3]<<24);
l&=0xffffffffl;
l|=((long)b[4]<<32);
l&=0xffffffffffl;
l|=((long)b[5]<<40);
l&=0xffffffffffffl;
l|=((long)b[6]<<48);
l|=((long)b[7]<<56);
return Double.longBitsToDouble(l);
}