Java Long to long2buff(long n)

Here you can find the source of long2buff(long n)

Description

long convert to buff (big-endian)

License

LGPL

Parameter

Parameter Description
n long number

Return

8 bytes buff

Declaration

public static byte[] long2buff(long n) 

Method Source Code

//package com.java2s;
/**/*w w w.j  ava  2  s  . c o m*/
* Copyright (C) 2008 Happy Fish / YuQing
*
* FastDFS Java Client may be copied only under the terms of the GNU Lesser
* General Public License (LGPL).
* Please visit the FastDFS Home Page http://www.csource.org/ for more detail.
**/

public class Main {
    /**
     * long convert to buff (big-endian)
     * 
     * @param n
     *            long number
     * @return 8 bytes buff
     */
    public static byte[] long2buff(long n) {
        byte[] bs;

        bs = new byte[8];
        bs[0] = (byte) ((n >> 56) & 0xFF);
        bs[1] = (byte) ((n >> 48) & 0xFF);
        bs[2] = (byte) ((n >> 40) & 0xFF);
        bs[3] = (byte) ((n >> 32) & 0xFF);
        bs[4] = (byte) ((n >> 24) & 0xFF);
        bs[5] = (byte) ((n >> 16) & 0xFF);
        bs[6] = (byte) ((n >> 8) & 0xFF);
        bs[7] = (byte) (n & 0xFF);

        return bs;
    }
}

Related

  1. long2Arr(long var, byte[] arrayBytes, int startIndex)
  2. long2array(int sz, long seed)
  3. long2char(long x)
  4. long2Date(Long date, String interval)
  5. long2dotted(long address)
  6. long2FourChars(long i)