Java Byte Array to Long bytes2long(byte[] byteArray, int offset)

Here you can find the source of bytes2long(byte[] byteArray, int offset)

Description

Convert an array of 8 bytes in a 64 bit long value in little endian order

License

Open Source License

Parameter

Parameter Description
byteArray byte array
offset start index in byte array

Return

the resulting 64 bit long value

Declaration

public final static long bytes2long(byte[] byteArray, int offset) 

Method Source Code

//package com.java2s;
/*/*from   w w w. j  a  va  2s.c  o  m*/
 * Helper Class for Catena v3.3 
 * 
 * Copyright (C) 2016  Axel von dem Bruch
 * 
 * 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; either
 * version 2.1 of the License, or (at your option) any later version.
 * 
 * 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.
 * 
 * See:  https://www.gnu.org/licenses/lgpl-2.1.html
 * You should have received a copy of the GNU General Public License 
 * along with this library.
 */

public class Main {
    /**
     * Convert an array of 8 bytes in a 64 bit long value
     * in little endian order
     * 
     * @param byteArray      byte array
     * @param offset      start index in byte array 
     * 
     * @return            the resulting 64 bit long value
     */
    public final static long bytes2long(byte[] byteArray, int offset) {

        return (((long) byteArray[offset] & 0xFF) | (((long) byteArray[offset + 1] & 0xFF) << 8)
                | (((long) byteArray[offset + 2] & 0xFF) << 16) | (((long) byteArray[offset + 3] & 0xFF) << 24)
                | (((long) byteArray[offset + 4] & 0xFF) << 32) | (((long) byteArray[offset + 5] & 0xFF) << 40)
                | (((long) byteArray[offset + 6] & 0xFF) << 48) | (((long) byteArray[offset + 7] & 0xFF) << 56));
    }
}

Related

  1. byte2Long(byte[] bytes, int offset)
  2. byte2long(byte[] data)
  3. byte2long(byte[] value, int count)
  4. byte2long(final byte[] v)
  5. bytes2long(byte[] b)
  6. bytes2long(byte[] bytes)
  7. bytes2long(byte[] bytes)
  8. bytes2Long(byte[] bytes)
  9. bytes2Long(byte[] bytes)