Java Long Number Create toLong(byte[] n)

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

Description

Converter

License

Open Source License

Parameter

Parameter Description
n a parameter

Declaration

public static long toLong(byte[] n) 

Method Source Code

//package com.java2s;
/*/*from   w w w  . j av a 2  s  .co m*/
 * Copyright 05-abr-2014 ?Deme
 *
 * This file is part of 'dmLang-8.1.0'.
 *
 * 'dmLang-8.1.0' 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.
 *
 * 'dmLang-8.1.0' 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 General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with 'dmLang-8.1.0'.  If not, see <http://www.gnu.org/licenses/>.
 */

public class Main {
    /**
     * Converter
     *
     * @param n
     * @return
     */
    public static long toLong(byte[] n) {
        long r = 0;
        long m = 1;
        for (int i = 0; i < 8; i++) {
            int b = n[i];
            if (b < 0) {
                b += 256;
            }
            r += b * m;
            m *= 256;
        }
        return r;
    }
}

Related

  1. toLong(byte[] data)
  2. toLong(byte[] in)
  3. toLong(byte[] input)
  4. toLong(byte[] key)
  5. toLong(byte[] memory, int index)
  6. toLong(byte[] readBuffer, int o)
  7. toLong(byte[] si, boolean isReverseOrder)
  8. toLong(byte[] src)
  9. toLong(byte[] src, int srcPos)