Shared.ByteUtils.ReadInt C# (CSharp) Method

ReadInt() public static method

public static ReadInt ( byte buffer, int offset ) : int
buffer byte
offset int
return int
        public static unsafe int ReadInt(byte[] buffer, int offset)
        {
            //var firstByte = buffer[offset];
            //var first = firstByte << 24;
            //var second = buffer[offset+1] << 16;
            //var third = buffer[offset+2] << 8;
            //var fourth = buffer[offset+3];

            fixed (byte* numPtr = &buffer[offset])
            {
                if ((offset & (4-1)) == 0)
                    return *(int*)numPtr;
                if (BitConverter.IsLittleEndian)
                    return (int)*numPtr | (int)numPtr[1] << 8 | (int)numPtr[2] << 16 | (int)numPtr[3] << 24;
                else
                    return (int)*numPtr << 24 | (int)numPtr[1] << 16 | (int)numPtr[2] << 8 | (int)numPtr[3];
            }

            //    return buffer[offset] << 24 | buffer[offset + 1] << 16 | buffer[offset + 2] << 8 | buffer[offset + 3];
        }