有一个长度为8的byte数组,如何将其转化为一个double类型的数值?
谢谢!

解决方案 »

  1.   

    double sum = Double.parseDouble(new String(byte[]));
      

  2.   

    /**
     * @author infon
     * 2007-5-16
     */
    public class Test { /**
     * @param args
     */
    public static void main(String[] args) {
    // TODO Auto-generated method stub
    byte[]from=new byte[]{1,2,3,4,5,6,7,8};
    StringBuffer tmp=new StringBuffer();
    for(int i=0;i<from.length;i++){
    tmp.append(from[i]);
    }
    double to=Double.valueOf(tmp.toString());
    System.out.println(to);
    }
    }
      

  3.   

    抱歉,没说清楚,byte数组中存储的是从低位到高位排列的double类型的16进制位,谢谢了。
      

  4.   

    java.math.BigInteger bi=new java.math.BigInteger(bs);
            double x=bi.doubleValue();
      

  5.   

    解决了,下面这个函数:Function for conversion of an 8 byte array to double: 
    public static double arr2double (byte[] arr, int start) {
    int i = 0;
    int len = 8;
    int cnt = 0;
    byte[] tmp = new byte[len];
    for (i = start; i < (start + len); i++) {
    tmp[cnt] = arr[i];
    //System.out.println(java.lang.Byte.toString(arr[i]) + " " + i);
    cnt++;
    }
    long accum = 0;
    i = 0;
    for ( int shiftBy = 0; shiftBy < 64; shiftBy += 8 ) {
    accum |= ( (long)( tmp[i] & 0xff ) ) << shiftBy;
    i++;
    }
    return Double.longBitsToDouble(accum);
    }谢谢大家了。to sunboy_yf():
    精度不会丢失把,都是8byte。