Q:

Output a = ~a + 2 << 1 ;

Please help out with understanding of the output of the following c program statement.
            a = ~a + 2 << 1 ;

            printf("Value of A is %d",a);

Value of A comes out to be -2.

A:

I am assuming that a is an signed int and initialized as 2. I am also assuming this is two's complement. (I have also omitted the bytes above the first byte as they don't have a meaning on the result of this answer).
The ~ (tilde) is the bitwise not operator. That is it will make any 1 into 0 and any 0 into 1. The << is a bit shift to the left operation.
So in the start we got 00000010 as the bits in a. As we do the not operator we get 11111101 which would give us the number -3.
We then add 2 to that so we get 11111111 or -1. We then bitshift this one to the left and we have 11111110 which equals -2.

