Java tutorial
//package com.java2s; //License from project: Open Source License public class Main { private static final int DOUBLE_SIZE = 8; private static final int BITS_IN_BYTE = 8; /** * Util method that converts a double into a byte array using a buffer. * * @param buffer The buffer to put the converted double * @param pos The position to start putting the converted double * @param input The double to convert */ public static void putDoubleToBytes(byte[] buffer, int pos, double input) { /* Get the double representation in order bitwise operations */ long value = Double.doubleToLongBits(input); /* Convert the double into array of bytes */ for (int i = pos; i < pos + DOUBLE_SIZE; i++) { buffer[i] = (byte) (value >> (((DOUBLE_SIZE - 1) - (i - pos)) * BITS_IN_BYTE)); } } }