answersLogoWhite

0


Best Answer

In C, the tilde operator (~) is the bitwise NOT operator. It returns the ones-complement of its operand. That is, the individual bits of the input are inverted in the output, such that all 0s becomes 1s and all 1s become 0s.

Note that the bitwise NOT (~) and logical NOT (!) operators are used for entirely different purposes. With logical NOT, the operator evaluates true (the all-ones bit pattern) when the operand is false (the all-zeroes bit pattern), which is exactly the same as the ones-complement used in bitwise NOT. However, if the operand represents anything other than the all-zeroes bit pattern, the output is the all-zeroes bit pattern.

We can compare the two operators by examining what happens to the bits in each operation. Let's use the value 42 (binary 00101010) as the input.

~42 -43

!42 false

Note that the binary value 11010101 represents -42 on a ones-complement system. However, most systems today use twos-complement notation for signed values, thus if we want to negate a value regardless of which notation is utilised by the system we must use the unary minus operator. On a twos-complement system, unary minus is equivalent to adding 1 to the ones-complement representation of the operand. Thus -42 is equivalent to (~42) + 1 = (~00101010) + 00000001 = 11010101 + 00000001 = 11010110 = -42.

User Avatar

Wiki User

7y ago
This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: What is tilde operator in c and how its work?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Related questions

What are the basic operator in turbo c?

+ += - -= * *= / /= % %= = == != <= >= & && | ^ ~ << <<= >> >>= , [] () are the basic operator in TURBO C


What is the operator that cannot be overloaded in c plus plus and java?

conditional operator , size of operator , membership operator and scope resulation operator can not be overload in c++


Use of scope resolution operator in C programming?

:: operator can not be used in C.


What is the memory management operator in c plus plus?

There is no memory management operator in C++ -- it is an unmanaged language. You use the C++ new operator to allocate memory, and use the C++ delete operator to release previously allocated memory.


Is it possible to do operator overloading in c?

No. Operator and/or function overloading is only a C++ thing.


What is condional operator?

Conditional Operator- Its the only ternary operator in c/c++.- Its syntax is-(condition)?statement1:statement2;-Shruti Jain


C coding for operator overloading?

C does not support operator overloading. If you mean C++ operator overloading, it depends on exactly what you wanted to do. If you wanted to '+' to strings, then you could write: string operator+(string a, string b) { // do something }


Which is dummy operator in c?

In C, the sizeof operator can be considered a dummy operator because it does not perform any operations on the data but simply returns the size in bytes of a variable or a data type.


What is THIS operator in c?

The this operator is not a c operator. It is a c++ keyword. It is equivalent to an r-value pointer to the current instance of an object. It is useful when resolving between object members and method parameters.


Example of binaray operator in c plus plus?

+ is an example, one of many, of a binary operator in C or C++ a = b + c; // for usage example


What is the operator of power in c plus plus?

There is no "power" operator in C or C++. You need to the use the math library function pow().


What do you have to major in to become a C and C operator?

C and C operation