Let us say a= 6 with binary representation as 00000110. By inverting its
bits, the signed bit becomes 1. Compiler now understands that the no. is a
negative no. so adds a negative sign and then converts it to its 2's
complement which is inverting its bits and adding 1 to it. Thus, the output
is 7.
a
00000110
b
11111001
As sign bit is 1
Converting it to its 2's complement,
0000110
+1
0000111
= -7
I think this is how it works. Please make ammends if I am wrong.
On Sun, Aug 7, 2011 at 5:10 PM, Shashank Jain <[email protected]> wrote:
> bitwise complement operator (~), complements d digits of d input bt when i
> use it :
>
> int a,b;
> b=~a;
>
> output: its giving o/p such that b= -a-1;
>
> why is dat so?
>
>
> Shashank Jain
> IIIrd year
> Computer Engineering
> Delhi College of Engineering
>
> --
> You received this message because you are subscribed to the Google Groups
> "Algorithm Geeks" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/algogeeks?hl=en.
>
--
You received this message because you are subscribed to the Google Groups
"Algorithm Geeks" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/algogeeks?hl=en.