Integer being a signed 16-bit number holds values between -2^15 t0 2^15-1 range. The maximum value being the one you have given in binary would be 0111 1111 1111 1111. So when you add one the result is 1111 1111 1111 1111. The left most bit being 1 represents -ve value and so the result value is the same with a -ve sign.This is the reason why you are getting that value.
I think the issue is that the compiler does not look at the values being added together. The compiler is simply checking syntax in this case. In that line you are trying to assign an int variable to the output of a + between 2 ints. The compiler doesn't perform the + so it can't know the size of the outcome.
Both assignment statements are allowed. [ February 24, 2006: Message edited by: Keith Lynn ]
10000000000000000000000000000000 is correct and it represents the value you got. You need to calculate 2's complement for this number since it has a 1 in the left most place which represents that its a negative number.
To calculate a 2's complement flip all the bits and add 1 to it.Whatever value you get keep a negative sign before it. The answer you are getting is correct and there are no errors anywhere.
compile won't say that the size can't fit into byte but it says the outcome of the above is an integer and we are trying to fit that to a byte .
By default, a whole number is considered to be an int.
There are cases where the compiler allows a direct assignment of an int to a byte.
But if you try this assignment
then the compiler will complain because what it sees is two ints being added together (even if the addends were bytes, they are going to be promoted to ints), and its not going to allow that to be assigned into a byte without a cast.