It is bitwise operator.
int i=2;
That is, in i's memory we will see 0000 0000 0000 0010
Similarlu. i=~4 means bitwise complements of ( 0000 0000 0000 0100)=1111 1111 1111 1011
Do refer 2's complement method. Computers uses now 2's complement approach
Here, most significant bit indicates that it is negative number. To get what is that number, we complement it and add 1
0000 0000 0000 0100
000000000000000001
-------------------------------
0000 0000 0000 0101 This is 5.
Thus, ~4 indicates -5.
Do read Morris Mano or some other books for knowing 2's complement approach

Positive: 50 %

Answer #3 | 28/12 2013 23:15

4 = 0000 0100 = 0 + 0 + 0 + 0 + 0 + 4 + 0 + 0 = 4
~4 = 1111 1011 = -128 + 64 + 32 + 16 + 8 + 0 + 2 + 1 = -5
When the first bit on the left of a signed integer is 1 the number becomes a negative number. Without going into too much detail about why it adds up that way, you can think of as starting at the lowest negative number and adding successive powers of two for each '1' in the string 1111 1011.

Answer #1| 28/12 2013 22:2750 %