Android Byte Array to Long Convert getLong(byte[] src, boolean bigEndin)

Here you can find the source of getLong(byte[] src, boolean bigEndin)

Description

get Long

Declaration

static protected long getLong(byte[] src, boolean bigEndin) 

Method Source Code

//package com.java2s;

public class Main {
    static protected long getLong(byte[] src, boolean bigEndin) {
        byte[] temp = { 0, 0, 0, 0, 0, 0, 0, 0 };
        for (int i = 0; i < src.length; i++) {
            if (i > 7)
                break;
            temp[i] = src[i];//from www  .j av  a2s.  co  m
        }
        if (!bigEndin) {
            return makeLong(temp[7], temp[6], temp[5], temp[4], temp[3],
                    temp[2], temp[1], temp[0]);
        } else {
            return makeLong(temp[4], temp[5], temp[6], temp[7], temp[0],
                    temp[1], temp[2], temp[3]);
        }
    }

    static private long makeLong(byte b7, byte b6, byte b5, byte b4,
            byte b3, byte b2, byte b1, byte b0) {
        return ((((long) b7 & 0xff) << 56) | (((long) b6 & 0xff) << 48)
                | (((long) b5 & 0xff) << 40) | (((long) b4 & 0xff) << 32)
                | (((long) b3 & 0xff) << 24) | (((long) b2 & 0xff) << 16)
                | (((long) b1 & 0xff) << 8) | (((long) b0 & 0xff) << 0));
    }
}

Related

  1. toLong(byte[] b, int pos)
  2. toLong(byte[] b, int pos, int width)
  3. toLong(byte[] src)
  4. toLong(byte[] src, int srcPos)
  5. makeLong(byte b7, byte b6, byte b5, byte b4, byte b3, byte b2, byte b1, byte b0)
  6. uint16ToLong(byte[] buf, int offset)
  7. uint32ToLong(byte[] buf, int offset)
  8. uint64ToLong(byte[] buf, int offset)
  9. byteArray2long(final byte[] number, final boolean swapHalfWord)