Here you can find the source of longToBytes(long lnum, byte[] bytes, int startIndex)
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. |
public static int longToBytes(long lnum, byte[] bytes, int startIndex)
//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; } }