- #include
//整形提升 - int main()
- {
- char a = 5;
- //字符型的内存大小为8个比特位,故在进行加法之类的线性运算时需要整形提升
- //00000000000000000000000000000101->5 因为字符型的内存大小不足,故在存放整形时需要裁切
- //00000101->5
- char b = 126;
- //00000000000000000000000001111110->126
- //01111110->126 同理
- char c = a + b;
- //00000000000000000000000000000101->5
- //00000000000000000000000001111110->126
- //00000000000000000000000010000011->5+126=131
- //10000011 裁切后
- printf("%d\n", c);
- //以整形输出时进行整形提升,因为第一位1被系统判定为符号位,故判断为负数,整形提升时要在前面补1
- //11111111111111111111111110000011 补码
- //11111111111111111111111110000010 反码
- //10000000000000000000000001111101 原码-> -125
- return 0;
- }