1

Possible Duplicate:
What is the tilde (~) in a C# enumeration?
What does the tilde mean in an expression?

I have download a CRC code snippet from the internet in C# having these lines:

byte[] hashBuffer = UInt32ToBigEndianBytes(~hash);

or

public static UInt32 Compute(byte[] buffer)
{
   return ~CalculateHash(InitializeTable(DefaultPolynomial), DefaultSeed, buffer, 0, buffer.Length);
}
Community
  • 1
  • 1
Patrick Peters
  • 9,261
  • 7
  • 55
  • 100

2 Answers2

7

The ~ operator performs a bitwise complement operation on its operand, which has the effect of reversing each bit. Bitwise complement operators are predefined for int, uint, long, and ulong.

From: http://msdn.microsoft.com/en-us/library/d2bd4x66.aspx

And although it is not used this way in the example you have shown, the ~ character is also used to declare a destructor in C#.

Cody Gray
  • 230,875
  • 49
  • 477
  • 553
Fredrik Leijon
  • 2,802
  • 18
  • 20
0

Take a look at MSDN: ~ Operator

Echilon
  • 9,829
  • 30
  • 130
  • 210
Martin Moser
  • 6,049
  • 1
  • 25
  • 39