Java Long to Byte Array longToByteArray(long number)

Here you can find the source of longToByteArray(long number)

Description

long to byte array,byte[8]

License

Apache License

Parameter

Parameter Description
number a parameter

Return

byte[]

Declaration

public static byte[] longToByteArray(long number) 

Method Source Code

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

public class Main {
    /**//from  w  w  w  . ja  v  a2 s .  c  om
     * long to byte array,byte[8]
     * 
     * @param number
     * @return byte[]
     */
    public static byte[] longToByteArray(long number) {
        byte[] byteArray = new byte[8];
        byteArray[7] = (byte) (number & 0xff);
        byteArray[6] = (byte) (number >> 8 & 0xff);
        byteArray[5] = (byte) (number >> 16 & 0xff);
        byteArray[4] = (byte) (number >> 24 & 0xff);
        byteArray[3] = (byte) (number >> 32 & 0xff);
        byteArray[2] = (byte) (number >> 40 & 0xff);
        byteArray[1] = (byte) (number >> 48 & 0xff);
        byteArray[0] = (byte) (number >> 56 & 0xff);
        return byteArray;
    }
}

Related

  1. longToByteArray(long input)
  2. longToByteArray(long l)
  3. longToByteArray(long l)
  4. longToByteArray(long l)
  5. longToByteArray(long longHi, long longLo, byte[] array, int offset)
  6. longToByteArray(long pSrc, byte[] pDst, int pOffset)
  7. longToByteArray(long source)
  8. longToByteArray(long v)
  9. longToByteArray(long value)