pls explain by showing bitwise operation it will be helpful to understand...Code:int main() { int a=1,b; b=~1; printf(""%d",b); return 0; }
thanks in advance.......
pls explain by showing bitwise operation it will be helpful to understand...Code:int main() { int a=1,b; b=~1; printf(""%d",b); return 0; }
thanks in advance.......
Please do your own homework. You can easily find a rather direct answer to this by searching the Web.
Look up a C++ Reference and learn How To Ask Questions The Smart WayOriginally Posted by Bjarne Stroustrup (2000-10-14)
Think it as binary:
What does NOT do:Code:00000000000000000000000000000001 // 1
Since you are declaring it as signed the compiler treats it are a little negative instead of a large positive.Code:11111111111111111111111111111110 // -2
Devoted my life to programming...
Think of the sign bit, only:
The sign bit can be a one or a zero. If the sign bit isn't a one, then it must be a zero, and vice-versa.
What else could a complement of a positive number be, since you've changed the sign bit?
Now apply that to all the bits in the binary for 1.
many many thanks to Sipher & Adak for their valuable time and lucid explanation...........