您的位置:首页 > 其它

逻辑移位与算术移位

2010-10-24 13:52 148 查看
#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;
}

[/code]
int强制转换的时候默认转化为有符号的数字
输入a,输出结果:

afun1(a)fun2(a)
127127127
128128-128
255255-1
25600
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: