I know in C# we can add 2 different integer types, say a variable of type int
to a variable of type long
eg
int i = 1;
long l = 2;
long l2 = i + l; //fine
How is this possible?
Because
since the int is of 32 bits if I were to have a negative integer the MSB will become 1
so:-
-1 will be represented as
10000000000000000000000000000001
(in signed magnitude way)
Now, my question is how does compiler gets to know that the above 32 bit number is -1
or 2147483649
?
And if it were to convert the 32 bit number to 64 bit isn't it going to loose the MSB resulting in getting wrong value?
If we do casting -1 in 32 bit becomes like this in 64 bit.
0000000000000000000000000000000010000000000000000000000000000001
loosing the MSB?
Hope you get my confusion.