static int IntFromBigEndian(byte[] buffer, int offset, int count) { if (count > 4) count = 4; int result = 0; for (int x = 0; x < count; x++) { int shift = 8 * (count - 1 - x); result = result | buffer[x + offset] << shift; } return result; } }