#include <conio.h> #include <stdio.h> int fun1 (unsigned word) { return (int) ((word << 24) >> 24); } int fun2 (unsigned word) { return ((int) word << 24) >>24; } int main() { unsigned a; while(1) { scanf("%d",&a); printf("%d,%d/n",fun1(a),fun2(a)); } getch(); return 0; }
int强制转换的时候默认转化为有符号的数字
输入a,输出结果:
a | fun1(a) | fun2(a) |
127 | 127 | 127 |
128 | 128 | -128 |
255 | 255 | -1 |
256 | 0 | 0 |