Java Byte Array to Long bytes2long(final byte[] bytes, final int start)

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

Description

Setup a long from an array of bytes.

License

Open Source License

Parameter

Parameter Description
bytes a parameter
start a parameter

Declaration

public static long bytes2long(final byte[] bytes, final int start) 

Method Source Code

//package com.java2s;
/*/*  w  ww  .j  a va  2 s  . com*/
 *    GeoTools - The Open Source Java GIS Toolkit
 *    http://geotools.org
 *
 *    (C) 2007-2008, Open Source Geospatial Foundation (OSGeo)
 *
 *    This library is free software; you can redistribute it and/or
 *    modify it under the terms of the GNU Lesser General Public
 *    License as published by the Free Software Foundation;
 *    version 2.1 of the License.
 *
 *    This library is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 *    Lesser General Public License for more details.
 */

public class Main {
    /**
     * Setup a long from an array of bytes.
     * @param bytes
     * @param start
     * @return
     */
    public static long bytes2long(final byte[] bytes, final int start) {
        int i = 0;
        final int length = 4;
        int count = 0;
        final byte[] tmp = new byte[length];
        for (i = start; i < (start + length); i++) {
            tmp[count] = bytes[i];
            count++;
        }
        long accum = 0;
        i = 0;
        for (int shiftBy = 0; shiftBy < 32; shiftBy += 8) {
            accum |= ((long) (tmp[i] & 0xff)) << shiftBy;
            i++;
        }
        return accum;
    }
}

Related

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