The one;s complement operator (~) is a unary operator that causes the bits of its operand to be inverted ( i. e. reversed) so that 1s becomes 0s and 0s becomes 1s. This operator always precedes its operand, The operand must be and integer-type. The one’s complement operator is sometimes referred to as the complementation operator. It is a member of the same precedence group as the other unary operations. Thus, its associativity is right to left. Now the following example illustrates the implementation of 1’s complement operator is a program,

**Source Code: **

#include <stdio.h>int main(){unsigned i = 0x7fff;printf("hexadecimal value: i = %x ~i = %x\n", i, ~i);printf("decimal value: i = %u ~i = %u\n", i, ~i);return 0;}

**Output**

hexadecimal value: i = 7fff ~i = ffff8000

decimal value: i = 32767 ~i = 4294934528

giving command and showing out put is compilers risk...but explanation wanted on how the compilers converts so..

ReplyDeletehi friends if N is a number ~N result is -(N+1).this is a standard formula.

ReplyDelete