Java Long to Byte Array longToBytes(long value, byte[] array, int offset)

Here you can find the source of longToBytes(long value, byte[] array, int offset)

Description

Writes a long as bytes into the provided array.

License

Open Source License

Parameter

Parameter Description
value the <code>long</code> to encode
array the write target
offset the offset in the array at which to write <code>value</code>

Declaration

public static void longToBytes(long value, byte[] array, int offset) 

Method Source Code

//package com.java2s;
/******************************************************************************
 * This program and the accompanying materials are made available under the
 * terms of the Eclipse Public License v1.0 which accompanies this
 * distribution, and is available at http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:/*w  ww  . j a v  a  2s. c  o m*/
 * Aggregate Knowledge - implementation
 ******************************************************************************/

public class Main {
    /**
     * Writes a <code>long</code> as <code>byte</code>s into the provided array.
     * @param value the <code>long</code> to encode
     * @param array the write target
     * @param offset the offset in the array at which to write <code>value</code>
     */
    public static void longToBytes(long value, byte[] array, int offset) {
        array[offset + 0] = (byte) (0xff & (value >> 56));
        array[offset + 1] = (byte) (0xff & (value >> 48));
        array[offset + 2] = (byte) (0xff & (value >> 40));
        array[offset + 3] = (byte) (0xff & (value >> 32));
        array[offset + 4] = (byte) (0xff & (value >> 24));
        array[offset + 5] = (byte) (0xff & (value >> 16));
        array[offset + 6] = (byte) (0xff & (value >> 8));
        array[offset + 7] = (byte) (0xff & value);
    }
}

Related

  1. longToBytes(long v, byte[] bytes)
  2. longToBytes(long v, final byte[] arr)
  3. longToBytes(long val)
  4. longToBytes(long val)
  5. longToBytes(long value)
  6. longToBytes(long value, byte[] buffer, int bufferStartPosition)
  7. longToBytes(long value, byte[] buffer, int offset)
  8. LongToBytes4(long l, byte abyte0[])
  9. LongToBytes8(long l)