Java Byte Array to Long bytesToLong(final byte[] bytes)

Here you can find the source of bytesToLong(final byte[] bytes)

Description

bytes To Long

License

Open Source License

Declaration

public static long bytesToLong(final byte[] bytes) 

Method Source Code

//package com.java2s;
/**//from w w w.  ja v a  2 s. co m
 *    Created on Oct 21, 2010
 *    This file is part of JObexFTP 2.0, and it contains parts of OBEX4J.
 *
 *    JObexFTP 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, either version 3 of the License, or
 *    (at your option) any later version.
 *
 *    JObexFTP 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.
 *
 *    You should have received a copy of the GNU Lesser General Public License
 *    along with JObexFTP.  If not, see <http://www.gnu.org/licenses/>.
 *
 */

public class Main {
    public static long bytesToLong(final byte[] bytes) {
        long result = 0;

        for (int i = 0; i < bytes.length; i++) {
            int temp = (int) bytes[i];
            if (temp < 0) {
                temp = 0x100 + temp;
            }
            result += temp << (8 * (bytes.length - 1 - i));
        }

        return result;
    }
}

Related

  1. bytesToLong(byte[] data, int offset)
  2. bytesToLong(byte[] inbytes, int shift)
  3. bytesToLong(byte[] longBytes)
  4. bytesToLong(byte[] p, int offset)
  5. bytesToLong(final byte[] b)
  6. bytesToLong(final byte[] bytes)
  7. bytesToLong(final byte[] data, final int offset)
  8. bytesToLongLE(byte[] bytes, int off)
  9. byteToLong(byte[] b)