Java Byte Array to Long bytesToLong(final byte[] data, final int offset)

Here you can find the source of bytesToLong(final byte[] data, final int offset)

Description

Undo #longToBytes(long) and reconstruct the long value.

License

Apache License

Declaration

public static long bytesToLong(final byte[] data, final int offset) 

Method Source Code

//package com.java2s;
/*/*from  www  . ja va 2 s .c o m*/
 * Copyright (C) 2010 Indeed Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
 * in compliance with the License. You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */

public class Main {
    /**
     * Undo {@link #longToBytes(long)} and reconstruct the long value.
     */
    public static long bytesToLong(final byte[] data, final int offset) {
        if (data == null) {
            return 0x0;
        }
        return (long) (0xff & data[offset + 0]) << 56 | (long) (0xff & data[offset + 1]) << 48
                | (long) (0xff & data[offset + 2]) << 40 | (long) (0xff & data[offset + 3]) << 32
                | (long) (0xff & data[offset + 4]) << 24 | (long) (0xff & data[offset + 5]) << 16
                | (long) (0xff & data[offset + 6]) << 8 | (long) (0xff & data[offset + 7]);
    }
}

Related

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