Android Byte Array to Long Convert readLong(byte[] buff, int pos)

Here you can find the source of readLong(byte[] buff, int pos)

Description

Read a long value from the byte array at the given position.

License

Open Source License

Parameter

Parameter Description
buff the byte array
pos the position

Return

the value

Declaration

public static long readLong(byte[] buff, int pos) 

Method Source Code

//package com.java2s;
/*/*w w  w.  j a  va 2s .  c o m*/
 * Copyright 2004-2008 H2 Group. Multiple-Licensed under the H2 License, Version 1.0, and under the Eclipse Public License, Version 1.0 (http://h2database.com/html/license.html). Initial Developer: H2 Group
 */

public class Main {
    /**
     * Read a long value from the byte array at the given position. The most significant byte is read first.
     * 
     * @param buff
     *          the byte array
     * @param pos
     *          the position
     * @return the value
     */
    public static long readLong(byte[] buff, int pos) {
        return ((long) (readInt(buff, pos)) << 32)
                + (readInt(buff, pos + 4) & 0xffffffffL);
    }

    public static int readInt(byte[] buff, int pos) {
        return (buff[pos++] << 24) + ((buff[pos++] & 0xff) << 16)
                + ((buff[pos++] & 0xff) << 8) + (buff[pos] & 0xff);
    }
}

Related

  1. uint32ToLong(byte[] buf, int offset)
  2. uint64ToLong(byte[] buf, int offset)
  3. byteArray2long(final byte[] number, final boolean swapHalfWord)
  4. parseLong(byte[] array, int offset, int multiplier, long[] result)
  5. parseLong(byte[] array, int offset, long[] result)