Java Long Number Create toLong(byte[] b, int off, boolean bigEndian)

Here you can find the source of toLong(byte[] b, int off, boolean bigEndian)

Description

to Long

License

Open Source License

Declaration

public static long toLong(byte[] b, int off, boolean bigEndian) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static long toLong(byte[] b, int off, boolean bigEndian) {
        if (bigEndian) {
            return (((long) (b[0] & 0xff)) << 56) | (((long) (b[1] & 0xff)) << 48) | (((long) (b[2] & 0xff)) << 40)
                    | (((long) (b[3] & 0xff)) << 32) | (((long) (b[4] & 0xff)) << 24)
                    | (((long) (b[5] & 0xff)) << 16) | (((long) (b[6] & 0xff)) << 8) | ((long) (b[7] & 0xff));
        } else {//w  ww.java2  s. c o  m
            return (((long) (b[7] & 0xff)) << 56) | (((long) (b[6] & 0xff)) << 48) | (((long) (b[5] & 0xff)) << 40)
                    | (((long) (b[4] & 0xff)) << 32) | (((long) (b[3] & 0xff)) << 24)
                    | (((long) (b[2] & 0xff)) << 16) | (((long) (b[1] & 0xff)) << 8) | ((long) (b[0] & 0xff));
        }
    }

    public static void toLong(long[] l, int lOff, byte[] b, int bOff, int bLen, boolean bigEndian) {
        int bEnd = bOff + bLen;
        for (int j = bOff, k = lOff; j < bEnd; j += 8, k++) {
            l[k] = toLong(b, j, bigEndian);
        }
    }
}

Related

  1. toLong(byte[] b)
  2. toLong(byte[] b)
  3. toLong(byte[] b)
  4. toLong(byte[] b)
  5. toLong(byte[] b)
  6. toLong(byte[] buf)
  7. toLong(byte[] buf)
  8. toLong(byte[] buf, int off)
  9. toLong(byte[] buf, int pos)