The ~ operator performs a bitwise complement operation on its operand. Bitwise complement operators are predefined for int, uint, long, and ulong.
User-defined types can overload the ~ operator (see operator).
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 | CLR 7.6.4 Bitwise complement operator