The ~ operator performs a bitwise complement operation on its operand. Bitwise complement operators are predefined for int, uint, long, and ulong.
~ expr
Where:
User-defined types can overload the ~ operator (see operator).
// cs_operator_bitwise_compl.cs
using System;
class Test
{
public static void Main()
{
Console.WriteLine("!0x{0:x8} = 0x{1:x8}", 8, ~8);
Console.WriteLine("!0x{0:x8} = 0x{1:x8}", -8, ~-8);
}
}
!0x00000008 = 0xfffffff7 !0xfffffff8 = 0x00000007
C# Operators |