Here you can find the source of byteToLong(byte[] b)
public static long byteToLong(byte[] b)
//package com.java2s; //License from project: Apache License public class Main { public static long byteToLong(byte[] b) { if (b.length == 1) { return b[0] & 0xFF; } else if (b.length == 2) { return (long) ((b[0] & 0xFF) << 8) | (long) (b[1] & 0xFF); } else if (b.length == 3) { return (long) ((b[0] & 0xFF) << 16) | (long) ((b[1] & 0xFF) << 8) | (long) (b[2] & 0xFF); } else if (b.length == 4) { return (long) ((b[0] & 0xFF) << 24) | (long) ((b[1] & 0xFF) << 16) | (long) ((b[2] & 0xFF) << 8) | (long) (b[3] & 0xFF); } else if (b.length == 5) { return (((long) b[0] & 0xFF) << 32) | (((long) b[1] & 0xFF) << 24) | (((long) b[2] & 0xFF) << 16) | (((long) b[3] & 0xFF) << 8) | ((long) b[4] & 0xFF); } else if (b.length == 6) { return (((long) b[0] & 0xFF) << 40) | (((long) b[1] & 0xFF) << 32) | (((long) b[2] & 0xFF) << 24) | (((long) b[3] & 0xFF) << 16) | (((long) b[4] & 0xFF) << 8) | ((long) b[5] & 0xFF); } else if (b.length == 7) { return (((long) b[0] & 0xFF) << 48) | (((long) b[1] & 0xFF) << 40) | (((long) b[2] & 0xFF) << 32) | (((long) b[3] & 0xFF) << 24) | (((long) b[4] & 0xFF) << 16) | (((long) b[5] & 0xFF) << 8) | ((long) b[6] & 0xFF); }/* ww w . j a va 2s. co m*/ 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); } public static long byteToLong(byte[] b, int offset, int length) { if (length == 1) { return b[offset + 0] & 0xFF; } else if (length == 2) { return (long) ((b[offset + 0] & 0xFF) << 8) | (long) (b[offset + 1] & 0xFF); } else if (length == 3) { return (long) ((b[offset + 0] & 0xFF) << 16) | (long) ((b[offset + 1] & 0xFF) << 8) | (long) (b[offset + 2] & 0xFF); } else if (length == 4) { return (long) ((b[offset + 0] & 0xFF) << 24) | (long) ((b[offset + 1] & 0xFF) << 16) | (long) ((b[offset + 2] & 0xFF) << 8) | (long) (b[offset + 3] & 0xFF); } else if (length == 5) { return (((long) b[offset + 0] & 0xFF) << 32) | (((long) b[offset + 1] & 0xFF) << 24) | (((long) b[offset + 2] & 0xFF) << 16) | (((long) b[offset + 3] & 0xFF) << 8) | ((long) b[offset + 4] & 0xFF); } else if (length == 6) { return (((long) b[offset + 0] & 0xFF) << 40) | (((long) b[offset + 1] & 0xFF) << 32) | (((long) b[offset + 2] & 0xFF) << 24) | (((long) b[offset + 3] & 0xFF) << 16) | (((long) b[offset + 4] & 0xFF) << 8) | ((long) b[offset + 5] & 0xFF); } else if (length == 7) { return (((long) b[offset + 0] & 0xFF) << 48) | (((long) b[offset + 1] & 0xFF) << 40) | (((long) b[offset + 2] & 0xFF) << 32) | (((long) b[offset + 3] & 0xFF) << 24) | (((long) b[offset + 4] & 0xFF) << 16) | (((long) b[offset + 5] & 0xFF) << 8) | ((long) b[offset + 6] & 0xFF); } return (((long) b[offset + 0] & 0xFF) << 56) | (((long) b[offset + 1] & 0xFF) << 48) | (((long) b[offset + 2] & 0xFF) << 40) | (((long) b[offset + 3] & 0xFF) << 32) | (((long) b[offset + 4] & 0xFF) << 24) | (((long) b[offset + 5] & 0xFF) << 16) | (((long) b[offset + 6] & 0xFF) << 8) | ((long) b[offset + 7] & 0xFF); } }