Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

//package com.java2s;
/*
 *  Copyright 2012 Peter Karich info@jetsli.de
 * 
 *  Licensed under the Apache License, Version 2.0 (the "License");
 *  you may not use this file except in compliance with the License.
 *  You may obtain a copy of the License at
 * 
 *       http://www.apache.org/licenses/LICENSE-2.0
 * 
 *  Unless required by applicable law or agreed to in writing, software
 *  distributed under the License is distributed on an "AS IS" BASIS,
 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 *  See the License for the specific language governing permissions and
 *  limitations under the License.
 */

public class Main {
    public static byte[] fromDouble(double value) {
        byte[] bytes = new byte[8];
        fromDouble(bytes, value, 0);
        return bytes;
    }

    public static void fromDouble(byte[] bytes, double value) {
        fromDouble(bytes, value, 0);
    }

    public static void fromDouble(byte[] bytes, double value, int offset) {
        fromLong(bytes, Double.doubleToRawLongBits(value), offset);
    }

    public static byte[] fromLong(long value) {
        byte[] bytes = new byte[8];
        fromLong(bytes, value, 0);
        return bytes;
    }

    public static void fromLong(byte[] bytes, long value) {
        fromLong(bytes, value, 0);
    }

    public static void fromLong(byte[] bytes, long value, int offset) {
        bytes[offset] = (byte) (value >>> 56);
        bytes[++offset] = (byte) (value >>> 48);
        bytes[++offset] = (byte) (value >>> 40);
        bytes[++offset] = (byte) (value >>> 32);
        bytes[++offset] = (byte) (value >>> 24);
        bytes[++offset] = (byte) (value >>> 16);
        bytes[++offset] = (byte) (value >>> 8);
        bytes[++offset] = (byte) (value);
    }
}