Java Long Number Create toLong(byte[] data)

Here you can find the source of toLong(byte[] data)

Description

Convert byte array to long

License

Open Source License

Parameter

Parameter Description
data - the byte array

Return

the long value

Declaration

public static long toLong(byte[] data) 

Method Source Code

//package com.java2s;
/**/*from  ww  w.j  a  v  a2 s.  c o  m*/
 * Syncnapsis Framework - Copyright (c) 2012-2014 ultimate
 * 
 * This program is free software; you can redistribute it and/or modify it under the terms of
 * the GNU General Public License as published by the Free Software Foundation; either version
 * 3 of the License, or any later version.
 * 
 * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MECHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Plublic License along with this program;
 * if not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Convert byte array to long
     * 
     * @param data - the byte array
     * @return the long value
     */
    public static long toLong(byte[] data) {
        if (data == null || data.length != 8)
            return 0x0;
        // (Below) convert to longs before shift because digits are lost with ints beyond the 32-bit
        // limit
        // @formatter:off
        return (long) ((long) (0xff & data[0]) << 56 | (long) (0xff & data[1]) << 48 | (long) (0xff & data[2]) << 40
                | (long) (0xff & data[3]) << 32 | (long) (0xff & data[4]) << 24 | (long) (0xff & data[5]) << 16
                | (long) (0xff & data[6]) << 8 | (long) (0xff & data[7]) << 0);
        // @formatter:on
    }
}

Related

  1. toLong(byte[] bytes, int index)
  2. toLong(byte[] bytes, int offset)
  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[] in)