public static uint BytesToUInt32(byte[] bytes, int offset)
{
if (bytes == null) throw new ArgumentNullException("bytes");
if ((bytes.Length <= offset + 0 || bytes.Length <= offset + 1 || bytes.Length <= offset + 2) &&
bytes.Length > offset + 3)
return
(uint) bytes[offset + 0] << 24 |
(uint) bytes[offset + 1] << 16 |
(uint) bytes[offset + 2] << 8 |
bytes[offset + 3];
}