What is the function of the operator?

Unfortunately, search engines did not help me using this query.

For example:

int foo = ~bar; 
+6
c ++ c operators c #
source share
8 answers

I assume that based on your most active tags, you are referencing C #, but this is the same NOT statement in C and C ++.

From MSDN :

The ~ operator performs a bitwise padding operation on the operand, which results in a bit. Bitwise padding operators are predefined for int, uint, long, and ULONG.

Program Example:

 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); } } 

Output:

 ~0x00000000 = 0xffffffff ~0x00000111 = 0xfffffeee ~0x000fffff = 0xfff00000 ~0x00008888 = 0xffff7777 ~0x22000022 = 0xddffffdd 
+11
source share

In C and C ++, this is a bitwise NOT .

+12
source share

It is called Tilde (for your future searches) and is usually the user for bitwise NOT (i.e. the addition of each bit)

+3
source share

It's called a tilde, and some languages โ€‹โ€‹seem to use it as bitwise NOT: http://en.wikipedia.org/wiki/Tilde#Computer_languages

+1
source share

This is usually the Negation operator. What is a language?

+1
source share

bitwise negation , gives a bitwise addition to the operand.

In many programming languages โ€‹โ€‹(including the C family), the bitwise NOT operator is "~" (tilde). This operator should not be confused with the operator "logical not", "!" (an exclamation mark), which in C ++ treats all value as a single Boolean - changing the true value to false and vice versa, and that C makes a value from 0 to 1 and a value other than 0 to 0. โ€œLogical is notโ€ is not bitwise.

+1
source share

In C, this is a bitwise complement operator. Basically, he looks at the binary representation of a number and converts it to zeros and zeros to ones.

0
source share

In most C-like languages, this is bitwise. This will result in a raw binary implementation of the number and change all values โ€‹โ€‹from 1 to 0 and from 0 to 1.

For example:

 ushort foo = 42; // 0000 0000 0010 1010 ushort bar = ~foo; // 1111 1111 1101 0101 Console.WriteLine(bar); // 65493 
0
source share

All Articles