Java Long to Byte Array long2bytes(long v)

Here you can find the source of long2bytes(long v)

Description

to byte array.

License

Apache License

Parameter

Parameter Description
v value.

Return

byte[].

Declaration

public static byte[] long2bytes(long v) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   w w w  .jav  a  2s . c o m*/
     * to byte array.
     * 
     * @param v value.
     * @return byte[].
     */
    public static byte[] long2bytes(long v) {
        byte[] ret = { 0, 0, 0, 0, 0, 0, 0, 0 };
        long2bytes(v, ret);
        return ret;
    }

    /**
     * to byte array.
     * 
     * @param v value.
     * @param b byte array.
     */
    public static void long2bytes(long v, byte[] b) {
        long2bytes(v, b, 0);
    }

    /**
     * to byte array.
     * 
     * @param v value.
     * @param b byte array.
     * @param off array offset.
     */
    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. long2Bytes(long l, byte[] target, int offset)
  2. long2bytes(long longValue)
  3. long2bytes(long num)
  4. long2Bytes(long num)
  5. long2Bytes(long num)
  6. long2bytes(long v, int len)
  7. long2bytes(long value)
  8. long2bytes(long value, byte[] bytes, int off)
  9. long2bytes(long value, byte[] bytes, int offset)