Java Byte Array to Long bytesToLong(byte[] array, int offset)

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

Description

Reconstructs a long from bytes that was encoded with #longToBytes(long,byte[],int) .

License

Open Source License

Parameter

Parameter Description
array the array of bytes
offset the offset in <code>array</code> to start reading from

Return

the encoded long

Declaration

public static long bytesToLong(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 a2  s .  c o  m*/
 * Aggregate Knowledge - implementation
 ******************************************************************************/

public class Main {
    /**
     * Reconstructs a <code>long</code> from <code>byte</code>s that was encoded
     * with {@link #longToBytes(long, byte[], int)}.
     *
     * @param  array the array of bytes
     * @param  offset the offset in <code>array</code> to start reading from
     * @return the encoded <code>long</code>
     */
    public static long bytesToLong(byte[] array, int offset) {
        long value = (long) array[offset + 0] & 0x00000000000000ff;
        value = (value << 8) | (array[offset + 1] & 0x00000000000000ff);
        value = (value << 8) | (array[offset + 2] & 0x00000000000000ff);
        value = (value << 8) | (array[offset + 3] & 0x00000000000000ff);
        value = (value << 8) | (array[offset + 4] & 0x00000000000000ff);
        value = (value << 8) | (array[offset + 5] & 0x00000000000000ff);
        value = (value << 8) | (array[offset + 6] & 0x00000000000000ff);
        value = (value << 8) | (array[offset + 7] & 0x00000000000000ff);

        return value;
    }
}

Related

  1. bytes2long(final byte[] bytes, final int start)
  2. bytesToLong(byte a, byte b, byte c, byte d)
  3. bytesToLong(byte a, byte b, byte c, byte d, byte e, byte f, byte g, byte h, boolean swapBytes)
  4. bytesToLong(byte[] a, int ao)
  5. bytesToLong(byte[] arr, int offset)
  6. bytesToLong(byte[] b)
  7. bytesToLong(byte[] b)
  8. bytesToLong(byte[] b)
  9. bytesToLong(byte[] bs)