C语言操作数截断
//测试截断 #include <stdio.h> int main() { int a = 0x80000001; unsigned int b = 0x80000001; printf("有符号数a的值是%d\n", a); printf("无符号数b的值是%x\n", b); //有符号数与无符号数的截断 short c = (short)a; short c1 = (short)b; printf("有符号数a截断后的值是%hd\n", c); printf("无符号数b截断后的值是%hd\n", c1); //补码截断 a = -1; printf("有符号数a的补码截断前的值是%x\n", a); short d = (short)a; short d1 = (short)b; printf("有符号数a的补码截断后的值是%hx\n", d); printf("有符号数a的补码截断后的值是%d\n", d); printf("无符号数b的补码截断后值是%hd\n", d1); return 0; }