You turn to your handy copy of ISO/IEC 23270:2006 — Information technology — Programming languages — C# and turn to §14.6.4 of the holy write. There you will find:
14.6.4 Bitwise complement operator
For an operation of the form ~x, unary operator overload resolution (§14.2.3) is applied to select a specific operator implementation. The operand is converted to the parameter type of the selected operator, and the type of the result is the return type of the operator. The predefined bitwise complement operators are:
int operator ~( int x ) ;
uint operator ~( uint x ) ;
long operator ~( long x ) ;
ulong operator ~( ulong x ) ;
For each of these operators, the result of the operation is the bitwise complement of x.
Every enumeration type E implicitly provides the following bitwise complement operator:
E operator ~(E x);
The result of evaluating ~x
, where x
is an expression of an enumeration type E
with an underlying type U
, is exactly the same as evaluating unchecked((E)(~(U)x))
. This operator is only considered by unary operator overload resolution when the operand type is the enum type E
(§14.2.3).
Lifted (§14.2.7) forms of the unlifted predefined bitwise complement operators defined above are also predefined.
In your case ~31
is the same as ~ 0x0000001F
. The bitwise complenent of 0x0000001F
is 0xFFFFFFE0
. Why they wouldn't just write the actual mask they wanted is beyond me.