Java Long to Byte Array longToBytes(long v)

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

Description

long To Bytes

License

Open Source License

Declaration

public static byte[] longToBytes(long v) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static byte[] longToBytes(long v) {
        byte[] data = new byte[8];
        int offset = 0;
        data[offset++] = (byte) ((v >> 56) & 0xFF);
        data[offset++] = (byte) ((v >> 48) & 0xFF);
        data[offset++] = (byte) ((v >> 40) & 0xFF);
        data[offset++] = (byte) ((v >> 32) & 0xFF);
        data[offset++] = (byte) ((v >> 24) & 0xFF);
        data[offset++] = (byte) ((v >> 16) & 0xFF);
        data[offset++] = (byte) ((v >> 8) & 0xFF);
        data[offset++] = (byte) (v & 0xFF);
        return data;
    }//from   w w  w .  j  a  va 2s  .  c o m
}

Related

  1. longToBytes(long n)
  2. longToBytes(long n, byte b[], int offset)
  3. longToBytes(long num)
  4. longToBytes(long num, byte[] data, int index)
  5. longToBytes(long number)
  6. longToBytes(long v)
  7. longToBytes(long v, byte[] b)
  8. longToBytes(long v, byte[] bytes)
  9. longToBytes(long v, final byte[] arr)