Why is a number sign-extended when it is cast to an unsigned type?
问题 I was studying how C stores data in memory by bit patterns. However I have confronted some issues when it comes to printf formatting. I have saved a variable as -10 (I do understand two's complement) and another variable as 246 . Those two variables have bit patterns of 11110110 (which is 0xF6 ). I was trying to print out a value using the unsigned int hexadecimal format in printf . char a = -10; unsigned char b = 246; printf("a : %x , b : %x\n" , (unsigned int) a, (unsigned int) b); //a :