Unfortunately, search engines have failed me using this query.
For instance:
int foo = ~bar;
Unfortunately, search engines have failed me using this query.
For instance:
int foo = ~bar;
It's called a tilde and it looks like some languages use it as a bitwise NOT: http://en.wikipedia.org/wiki/Tilde#Computer%5Flanguages
It's called Tilde (for your future searches), and is usually user for bitwise NOT (i.e. the complement of each bit)
bitwise negation, yields the bitwise complement of the operand.
In many programming languages (including those in the C family), the bitwise NOT operator is "~" (tilde). This operator must not be confused with the "logical not" operator, "!" (exclamation point), which in C++ treats the entire value as a single Boolean—changing a true value to false, and vice versa, and that C makes a value of 0 to 1 and a value other than 0 to 0. The "logical not" is not a bitwise operation.
In C, it's the bitwise complement operator. Basically, it looks at the binary representation of a number and converts the ones into zeros and the zeros into ones.
I'm assuming based on your most active tags you're referring to C#, but it's the same NOT
operator in C and C++ as well.
From MSDN:
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.
static void Main()
{
int[] values = { 0, 0x111, 0xfffff, 0x8888, 0x22000022};
foreach (int v in values)
{
Console.WriteLine("~0x{0:x8} = 0x{1:x8}", v, ~v);
}
}
~0x00000000 = 0xffffffff
~0x00000111 = 0xfffffeee
~0x000fffff = 0xfff00000
~0x00008888 = 0xffff7777
~0x22000022 = 0xddffffdd
In most C-like languages, it is a bitwise not. This will take the raw binary implementation of a number, and change all 1's to 0's and 0's to 1's.
For example:
ushort foo = 42; // 0000 0000 0010 1010
ushort bar = ~foo; // 1111 1111 1101 0101
Console.WriteLine(bar); // 65493