int 在内存中是以小端方式存储,根硬件有关系
unsigned char & signed char
signed short & unsigned short
signed short:-32768~32767
unsigned short:0~65536
整形提升
char a = -1;
printf("%d",a);//-1
//-1的补码: 10000000 00000000 00000000 00000001
//-1的反码: 11111111 11111111 11111111 11111110
//-1的源码: 11111111 11111111 11111111 11111111
//截断
//11111111 a
//整形提升
//11111111 11111111 11111111 11111111 内存中的补码 有符号前面补1
//10000000 00000000 00000000 00000000 反码
//10000000 00000000 00000000 00000001 源码
unsigned char c = -1;
printf("%d",c);//255
//-1的补码: 10000000 00000000 00000000 00000001
//-1的反码: 11111111 11111111 11111111 11111110
//-1的源码: 11111111 11111111 11111111 11111111
//截断
//11111111 c
//00000000 00000000 00000000 00000000 11111111 无符号前面补0
//正数:源=反=补 所以c=255
int main()
{
char a = -128;
printf("%u",a);//4294967168 无符号
printf("%d", a);//-128 有符号
//无符号
//-128补码 00000000 00000000 00000000 10000000
//-128反码 11111111 11111111 11111111 01111111
//-128源码 11111111 11111111 11111111 10000000
//有符号
// 截断
// 10000000
//-128补码 11111111 11111111 11111111 10000000
//-128反码 10000000 00000000 00000000 01111111
//-128源码 10000000 00000000 00000000 10000000
return 0;
}
char d = 128;
printf("%u",d);//4294967168
//128源码 00000000 00000000 00000000 10000000
//10000000
//11111111 11111111 11111111 10000000 无符号:源=反=补
printf("%d", d);//-128
//11111111 11111111 11111111 10000000
//10000000 00000000 00000000 01111111
//10000000 00000000 00000000 10000000 -128