private static void toBytes(final double value, final ByteOrder byteOrder, final byte[] result, final int offset) {
        final long bits = Double.doubleToRawLongBits(value);
        if (byteOrder == ByteOrder.LITTLE_ENDIAN) {
            result[offset + 0] = (byte) (0xff & bits >> 0);
            result[offset + 1] = (byte) (0xff & bits >> 8);
            result[offset + 2] = (byte) (0xff & bits >> 16);
            result[offset + 3] = (byte) (0xff & bits >> 24);
            result[offset + 4] = (byte) (0xff & bits >> 32);
            result[offset + 5] = (byte) (0xff & bits >> 40);
            result[offset + 6] = (byte) (0xff & bits >> 48);
            result[offset + 7] = (byte) (0xff & bits >> 56);
        } else {
            result[offset + 7] = (byte) (0xff & bits >> 0);
            result[offset + 6] = (byte) (0xff & bits >> 8);
            result[offset + 5] = (byte) (0xff & bits >> 16);
            result[offset + 4] = (byte) (0xff & bits >> 24);
            result[offset + 3] = (byte) (0xff & bits >> 32);
            result[offset + 2] = (byte) (0xff & bits >> 40);
            result[offset + 1] = (byte) (0xff & bits >> 48);
            result[offset + 0] = (byte) (0xff & bits >> 56);
        }
    }
Convenience methods for converting data types to and from byte arrays.
src/main/java/org/apache/commons/imaging/common/ByteConversions.java