Here you can find the source of toBytesLittleEndian(long value, int cnt)
Parameter | Description |
---|---|
value | the long to convert. |
cnt | the number of bytes to convert. |
public static byte[] toBytesLittleEndian(long value, int cnt)
//package com.java2s; /*************************************************************************** * Copyright (C) 2001, Patrick Charles and Jonas Lehmann * * Distributed under the Mozilla Public License * * http://www.mozilla.org/NPL/MPL-1.1.txt * ***************************************************************************/ public class Main { /**//w w w. j a v a 2 s .com * Convert a long integer into an array of bytes, little endian format. * (i.e. this does the same thing as toBytes() but returns an array * in reverse order from the array returned in toBytes(). * @param value the long to convert. * @param cnt the number of bytes to convert. */ public static byte[] toBytesLittleEndian(long value, int cnt) { byte[] bytes = new byte[cnt]; for (int i = 0; i < cnt; i++) { bytes[i] = (byte) (value & 0xff); value >>= 8; } return bytes; } }