Java Byte Array to Long bytesToLong(byte[] b)

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

Description

Converts a byte[] to a long

License

Open Source License

Parameter

Parameter Description
b Bytes to convert to a long

Return

The byte[] in long form

Declaration

public static long bytesToLong(byte[] b) 

Method Source Code

//package com.java2s;
/*// w  w w .j av a2  s. c o  m
 * This file is part of SpaceModule (http://spacebukkit.xereo.net/).
 *
 * SpaceModule is free software: you can redistribute it and/or modify it under the terms of the
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license as published by the Creative
 * Common organization, either version 3.0 of the license, or (at your option) any later version.
 *
 * SpaceBukkit 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
 * Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA) license for more details.
 *
 * You should have received a copy of the Attribution-NonCommercial-ShareAlike Unported (CC BY-NC-SA)
 * license along with this program. If not, see <http://creativecommons.org/licenses/by-nc-sa/3.0/>.
 */

public class Main {
    /**
     * Converts a byte[] to a long
     * @param b Bytes to convert to a long
     * @return The byte[] in long form
     */
    public static long bytesToLong(byte[] b) {
        long l = 0L;
        l = b[0];
        l = (l << 8) | b[1];
        l = (l << 8) | b[2];
        l = (l << 8) | b[3];
        l = (l << 8) | b[4];
        l = (l << 8) | b[5];
        l = (l << 8) | b[6];
        l = (l << 8) | b[7];
        return l;
    }
}

Related

  1. bytesToLong(byte a, byte b, byte c, byte d)
  2. bytesToLong(byte a, byte b, byte c, byte d, byte e, byte f, byte g, byte h, boolean swapBytes)
  3. bytesToLong(byte[] a, int ao)
  4. bytesToLong(byte[] arr, int offset)
  5. bytesToLong(byte[] array, int offset)
  6. bytesToLong(byte[] b)
  7. bytesToLong(byte[] b)
  8. bytesToLong(byte[] bs)
  9. bytesToLong(byte[] buf, int offset, int length, boolean asc)