Java Byte Array Create toBytesLittleEndian(long value, int cnt)

Here you can find the source of toBytesLittleEndian(long value, int cnt)

Description

Convert a long integer into an array of bytes, little endian format.

License

Mozilla Public License

Parameter

Parameter Description
value the long to convert.
cnt the number of bytes to convert.

Declaration

public static byte[] toBytesLittleEndian(long value, int cnt) 

Method Source Code

//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;
    }
}

Related

  1. toBytesFromOct(String octSymbols)
  2. toBytesFromString(String s)
  3. toBytesFromUnicode(String s)
  4. toBytesHexEscaped(final byte[] s, final int off, final int len)
  5. toBytesInt32BE(int w)
  6. toBytesOctalEscaped(final byte[] s, final int off, final int len)
  7. toBytesShortBE(short w)
  8. toBytesString(byte[] bytes)
  9. toByteString(byte[] bytes, String seperator)