Here you can find the source of bytesToDouble(byte[] bytes, int startIndex)
Parameter | Description |
---|---|
bytes | the byte array |
startIndex | the starting index of the array where the long is stored. |
public static double bytesToDouble(byte[] bytes, int startIndex)
//package com.java2s; //License from project: Open Source License public class Main { /**//from w w w . ja va 2 s .co m * Given an array of bytes, convert it to a double, least significant byte is stored in the beginning. * * @param bytes * the byte array * @param startIndex * the starting index of the array where the long is stored. * @ret the double result. */ public static double bytesToDouble(byte[] bytes, int startIndex) { return Double.longBitsToDouble(bytesToLong(bytes, startIndex)); } /** * Given an array of bytes, convert it to a long, least significant byte is stored in the beginning. * * @param bytes * the byte array * @param startIndex * the starting index of the array where the long is stored. * @ret the long result. */ public static long bytesToLong(byte[] bytes, int startIndex) { // the lower 4 bytes // long temp = (long)bytesToInt(bytes, startIndex) & (long)0xffffffff; // return temp | ((long)bytesToInt(bytes, startIndex+4) << 32); return (((long) bytes[startIndex] & 0xff) | (((long) bytes[startIndex + 1] & 0xff) << 8) | (((long) bytes[startIndex + 2] & 0xff) << 16) | (((long) bytes[startIndex + 3] & 0xff) << 24) | (((long) bytes[startIndex + 4] & 0xff) << 32) | (((long) bytes[startIndex + 5] & 0xff) << 40) | (((long) bytes[startIndex + 6] & 0xff) << 48) | (((long) bytes[startIndex + 7] & 0xff) << 56)); } }