Java Long to Byte Array longToBytes(long lnum, byte[] bytes, int startIndex)

Here you can find the source of longToBytes(long lnum, byte[] bytes, int startIndex)

Description

Given a long, convert it into a byte array

License

Open Source License

Parameter

Parameter Description
lnum the long given to convert
bytes the bytes where to store the result
startIndex the starting index of the array where the result is stored.

Declaration

public static int longToBytes(long lnum, byte[] bytes, int startIndex) 

Method Source Code

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

public class Main {
    /**//w w  w. ja v  a  2s.  c  o m
     * Given a long, convert it into a byte array
     * 
     * @param lnum
     *            the long given to convert
     * @param bytes
     *            the bytes where to store the result
     * @param startIndex
     *            the starting index of the array where the result is stored.
     * @ret the index of the array after storing this long
     */
    public static int longToBytes(long lnum, byte[] bytes, int startIndex) {
        for (int i = 0; i < 8; i++)
            bytes[startIndex + i] = (byte) ((lnum >> (i * 8)) & 0xff);
        return startIndex + 8;
    }
}

Related

  1. longToBytes(long l, byte[] b)
  2. longToBytes(long l, byte[] bytes, int offset)
  3. longToBytes(long l, byte[] data, int[] offset)
  4. longToBytes(long l, byte[] result)
  5. longToBytes(long ldata, int n)
  6. longToBytes(long n)
  7. longToBytes(long n)
  8. longToBytes(long n, byte b[], int offset)
  9. longToBytes(long num)