Here you can find the source of bytesToDouble(byte[] buffer)
Parameter | Description |
---|---|
buffer | The byte array containing the double. |
static public double bytesToDouble(byte[] buffer)
//package com.java2s; /************************************************************************ * Copyright (c) Crater Dog Technologies(TM). All Rights Reserved. * ************************************************************************ * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. * * * * This code is free software; you can redistribute it and/or modify it * * under the terms of The MIT License (MIT), as published by the Open * * Source Initiative. (See http://opensource.org/licenses/MIT) * ************************************************************************/ public class Main { /**// www. j av a2 s.c o m * This function converts the bytes in a byte array to its corresponding double value. * * @param buffer The byte array containing the double. * @return The corresponding double value. */ static public double bytesToDouble(byte[] buffer) { return bytesToDouble(buffer, 0); } /** * This function converts the bytes in a byte array at the specified index to its * corresponding double value. * * @param buffer The byte array containing the double. * @param index The index for the first byte in the byte array. * @return The corresponding double value. */ static public double bytesToDouble(byte[] buffer, int index) { double real; long bits = bytesToLong(buffer, index); real = Double.longBitsToDouble(bits); return real; } /** * This function converts the bytes in a byte array to its corresponding long value. * * @param buffer The byte array containing the long. * @return The corresponding long value. */ static public long bytesToLong(byte[] buffer) { return bytesToLong(buffer, 0); } /** * This function converts the bytes in a byte array at the specified index to its * corresponding long value. * * @param buffer The byte array containing the long. * @param index The index for the first byte in the byte array. * @return The corresponding long value. */ static public long bytesToLong(byte[] buffer, int index) { int length = buffer.length - index; if (length > 8) length = 8; long l = 0; for (int i = 0; i < length; i++) { l |= ((buffer[index + length - i - 1] & 0xFFL) << (i * 8)); } return l; } }