Java Double Convert to convertDoubleFromBytes(final byte[] bytes)

Here you can find the source of convertDoubleFromBytes(final byte[] bytes)

Description

convert Double From Bytes

License

Open Source License

Declaration

public static double convertDoubleFromBytes(final byte[] bytes) 

Method Source Code

//package com.java2s;
/**/*  w  ww  . j  a v  a2  s  . c  om*/
 * Copyright (c) 2008-2012 Ardor Labs, Inc.
 *
 * This file is part of Ardor3D.
 *
 * Ardor3D is free software: you can redistribute it and/or modify it 
 * under the terms of its license which may be found in the accompanying
 * LICENSE file or at <http://www.ardor3d.com/LICENSE>.
 */

public class Main {
    public static double convertDoubleFromBytes(final byte[] bytes) {
        return convertDoubleFromBytes(bytes, 0);
    }

    public static double convertDoubleFromBytes(final byte[] bytes, final int offset) {
        // Convert it to a double
        final long bits = convertLongFromBytes(bytes, offset);
        return Double.longBitsToDouble(bits);
    }

    public static long convertLongFromBytes(final byte[] bytes) {
        return convertLongFromBytes(bytes, 0);
    }

    public static long convertLongFromBytes(final byte[] bytes, final int offset) {
        // Convert it to an long
        return ((((long) bytes[offset + 7]) & 0xFF) + ((((long) bytes[offset + 6]) & 0xFF) << 8)
                + ((((long) bytes[offset + 5]) & 0xFF) << 16) + ((((long) bytes[offset + 4]) & 0xFF) << 24)
                + ((((long) bytes[offset + 3]) & 0xFF) << 32) + ((((long) bytes[offset + 2]) & 0xFF) << 40)
                + ((((long) bytes[offset + 1]) & 0xFF) << 48) + ((((long) bytes[offset + 0]) & 0xFF) << 56));
    }
}

Related

  1. convertDouble(String str)
  2. convertDouble(String str, double defaults)
  3. convertDouble2double(final Double[] pArray)
  4. convertDoubleArrayToString(double[] value, String separator)
  5. convertDoubleConsonant(byte[] b)
  6. convertDoubleIntoHexadecimalString(double value, int precision)
  7. convertDoubleList(Double[] list)
  8. convertDoubleMatrixToFloat(double[][] input, int dimRows, int dimColoumns)
  9. convertDoubleNumberFromSciNotation(String numberInScientificNotation)