Java tutorial
//package com.java2s; public class Main { public static long parseNumber(byte[] buf, int len, boolean bigEndian) { if (buf == null || buf.length == 0) { throw new IllegalArgumentException("byte array is null or empty!"); } int mlen = Math.min(len, buf.length); long r = 0; if (bigEndian) for (int i = 0; i < mlen; i++) { r <<= 8; r |= (buf[i] & 0xff); } else for (int i = mlen - 1; i >= 0; i--) { r <<= 8; r |= (buf[i] & 0xff); } return r; } }