Java Double to Byte Array double2bytes(double v, byte[] b)

Here you can find the source of double2bytes(double v, byte[] b)

Description

doublebytes

License

Apache License

Declaration

public static void double2bytes(double v, byte[] b) 

Method Source Code

//package com.java2s;
/**//from w  w w  .  ja v  a2  s  .  com
 * Copyright [2009-2010] [dennis zhuang(killme2008@gmail.com)]
 * 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[] double2bytes(double v) {
        byte[] ret = { 0, 0, 0, 0, 0, 0, 0, 0 };
        double2bytes(v, ret);
        return ret;
    }

    public static void double2bytes(double v, byte[] b) {
        double2bytes(v, b, 0);
    }

    public static void double2bytes(double v, byte[] b, int off) {
        long l = Double.doubleToLongBits(v);
        long2bytes(l, b, off);
    }

    public static byte[] long2bytes(long v) {
        byte[] ret = { 0, 0, 0, 0, 0, 0, 0, 0 };
        long2bytes(v, ret);
        return ret;
    }

    public static void long2bytes(long v, byte[] b) {
        long2bytes(v, b, 0);
    }

    public static void long2bytes(long v, byte[] b, int off) {
        b[off + 7] = (byte) v;
        b[off + 6] = (byte) (v >>> 8);
        b[off + 5] = (byte) (v >>> 16);
        b[off + 4] = (byte) (v >>> 24);
        b[off + 3] = (byte) (v >>> 32);
        b[off + 2] = (byte) (v >>> 40);
        b[off + 1] = (byte) (v >>> 48);
        b[off + 0] = (byte) (v >>> 56);
    }
}

Related

  1. double2bytearray(double rastervalue)
  2. double2bytes(double v)
  3. double2bytes(double v, int len)
  4. double2bytes(double value)
  5. double2bytes(double x)
  6. double2bytesLE(double val, byte[] b, int off)