Java Array to Long arrayToLong(final byte[] array, final int start)

Here you can find the source of arrayToLong(final byte[] array, final int start)

Description

Convert the contents of the specified array to a long, starting at an offset of start.

License

Open Source License

Parameter

Parameter Description
array a parameter
start a parameter

Return

long

Declaration


public static long arrayToLong(final byte[] array, final int start) 

Method Source Code

//package com.java2s;
// it under the terms of the GNU General Public License as published by

public class Main {
    private static final int MASK_FF = 0xff;

    /***********************************************************************************************
     * Convert the contents of the specified array to a <code><b>long</b></code>,
     * starting at an offset of <code>start</code>.
     */* www .j  av  a  2s. c  o m*/
     * @param array
     * @param start
     *
     * @return long
     */

    public static long arrayToLong(final byte[] array, final int start) {
        int i;
        int count;
        long accum;
        final int length;
        final byte[] temp;

        count = 0;
        length = 4;
        temp = new byte[length];

        for (i = start; i < (start + length); i++) {
            temp[count] = array[i];
            count++;
        }

        accum = 0;
        i = 0;

        for (int shiftBy = 0; shiftBy < 32; shiftBy += 8) {
            accum |= ((long) (temp[i] & MASK_FF)) << shiftBy;
            i++;
        }

        return (accum);
    }
}

Related

  1. arrayToLong(final int[] digits)
  2. arrayToLongString(T[] array)