int main(void)
{
char x1 = 0x81;
char x2 = 0x1;
int a, b;
a = x1+x2;
b = (a>>8) & 0xFF;
printf("a = %d, b = %d",a, b);
return 0;
}
Why do I get the results a = -126 and b = 255 ?
x1 is 1000 0001
x2 is 0000 0001
Sum = 1000 0010, thus it's 130. But, because it's the case with "char", 130 exceeds the maximum possible value represented on 8 bit (128). What can I do in this case ? Thanks.