Java Long to longToLittleEndianBytes(long value, byte[] destination, int offset, int length)

Here you can find the source of longToLittleEndianBytes(long value, byte[] destination, int offset, int length)

Description

Converts a long to the array of bytes in the little endian format.

License

Open Source License

Parameter

Parameter Description
value The long value to be converted to the array of bytes.
destination The byte array to where the result is stored.
offset The offset in the result array from where the result bytes are stored onwards.
length The number of bytes to store the result.

Declaration

public static void longToLittleEndianBytes(long value, byte[] destination, int offset, int length) 

Method Source Code

//package com.java2s;
/*/*from   w  ww . j a  va  2s.  co  m*/
* Copyright (c) 2005 Nokia Corporation and/or its subsidiary(-ies).
* All rights reserved.
* This component and the accompanying materials are made available
* under the terms of "Eclipse Public License v1.0"
* which accompanies this distribution, and is available
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
*
* Initial Contributors:
* Nokia Corporation - initial contribution.
*
* Contributors:
*
* Description:  Helper class containing common non-HTI-specific helper
*                functions that can be used in other java classes.
*
*/

public class Main {
    /**
     * Converts a long to the array of bytes in the little endian format.
     *
     * @param value         The long value to be converted to the
     *                      array of bytes.
     * @param destination   The byte array to where the result is stored.
     * @param offset        The offset in the result array from where the
     *                      result bytes are stored onwards.
     * @param length        The number of bytes to store the result.
     */
    public static void longToLittleEndianBytes(long value, byte[] destination, int offset, int length) {
        int shiftBits = 0;

        for (int i = 0; i < length; i++) {
            destination[offset + i] = (byte) ((value >> shiftBits) & 0xFF);
            shiftBits += 8;
        }
    }
}

Related

  1. longToDB(long val)
  2. longToEightBytes(final long value)
  3. longToFourBytes(long value)
  4. longToFrontInt(long data)
  5. longToLex(long v)
  6. longToN62(long l)
  7. longToName(long l)
  8. longToNBuf(long l, char[] chars)
  9. longToNetworkByteOrderArray(long addr)