Java Long Number Create toLong(byte[] bytes, int offset)

Here you can find the source of toLong(byte[] bytes, int offset)

Description

Convert a byte array to a long value

License

Open Source License

Parameter

Parameter Description
bytes a parameter
offset a parameter

Return

the long value corresponding to the 8 first bytes of the byte array

Declaration

public static long toLong(byte[] bytes, int offset) 

Method Source Code

//package com.java2s;
/*/*from  w ww . j av  a2 s .c om*/
 * This file is part of org.kalmeo.util.
 * 
 * org.kalmeo.util 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.
 * 
 * org.kalmeo.util 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 org.kalmeo.util.  If not, see <http://www.gnu.org/licenses/>.
 *  
 * Creation date : 17 janv. 08
 * Copyright (c) Kalmeo 2007-2008. All rights reserved.
 * http://www.kalmeo.org
 */

public class Main {
    /**
     * Convert a byte array to a long value
     * 
     * @param bytes
     * @param offset
     * @return the long value corresponding to the 8 first bytes of the byte
     *         array
     */
    public static long toLong(byte[] bytes, int offset) {
        int value = 0;
        if (bytes != null && bytes.length >= 8) {
            for (int i = 0; i < 8; ++i) {
                value += (0x000000FF & bytes[offset + i]) << ((7 - i) * 8);
            }
        }
        return value;
    }
}

Related

  1. toLong(byte[] bytes, int index)
  2. toLong(byte[] bytes, int index)
  3. toLong(byte[] bytes, int offset)
  4. ToLong(byte[] bytes, int offset)
  5. toLong(byte[] bytes, int offset)
  6. toLong(byte[] data)
  7. toLong(byte[] data)
  8. toLong(byte[] data)
  9. toLong(byte[] data)