Here you can find the source of bytes2long(final byte[] bytes, final int start)
Parameter | Description |
---|---|
bytes | a parameter |
start | a parameter |
public static long bytes2long(final byte[] bytes, final int start)
//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; } }