Here you can find the source of bytesToInt(byte[] bytesSource)
public static int bytesToInt(byte[] bytesSource)
//package com.java2s; //License from project: Apache License public class Main { public static int bytesToInt(byte[] bytesSource) { int num = 0; num |= (0xFF & bytesSource[0]); int i = 0; while (i++ < bytesSource.length - 1) { num = (num << 8) | (0xFF & bytesSource[i]); }/* w ww .ja v a2s . co m*/ return num; } public static int bytesToInt(byte[] bytesSource, int offset, int length) { if (length <= 0 || length > 4) { throw new IllegalArgumentException("Expected range of length is (0,4], but the input is:" + length); } int num = 0; num |= (0xFF & bytesSource[offset]); int i = 0; while (i++ < length - 1 && i + offset < bytesSource.length) { num = (num << 8) | (0xFF & bytesSource[i + offset]); } return num; } }