unsigned char j=130;
printf("uchar j=%d\n",j); //j=130
unsigned char转换为int时考虑全部8位
unsigned char m=130;
printf("uchar m=%d\n",(char)m); //m=-126
unsigned char转换为了char,最高位为符号位
(130[原]=1000 0010,130[补]=1111 1110)
char k=130;
printf("char k=%d\n",k); //k=-126
同上一条
char i=-7;
printf("char i=%u\n",(char)i); //i=4294967289=2^32-1-6
printf("char i=%u\n",(unsigned char)i); //i=249=2^8-1-6
负数值的char 赋给无符号整数,高位会填充全1;
先转换为unsigned char, 则自身的8位即为无符号数,再赋给无符号整数,则高位填充0
(-7[原]=1000 0111,-7[补]=1111 1001)
unsigned char n=-7;
printf("uchar n=%u\n",n); //i=249
同上一条
小结:其实char与unsigned char中存储的二进制是相同的,只是作为char时最高位代表了符号