逻辑右移 算术右移

逻辑右移就是不考虑符号位,右移一位,左边补零即可。
算术右移需要考虑符号位,右移一位,若符号位为1,就在左边补1,;否则,就补0。

没有特别说明,就是逻辑移动

左移:一般都是逻辑左移

右移:有符号数算术右移,无符号数逻辑右移

#include<stdio.h>
#include<string.h>


int fun1(unsigned int word)
{
return (int)((word<<24)>>24);    //先逻辑左移,再逻辑右移
}
int fun2(unsigned int word)
{
return ((int)word <<24 )>>24;    //先逻辑左移 ,再算术右移
}


int main()
{
unsigned int word1 = 0x00000076;        //0x00000076 0x00000076
unsigned int word2 = 0x87654321;//0x00000021  0x00000021
unsigned int word3 = 0x000000C9;//0x000000c9 0xFFFFFFc9
unsigned int word4 = 0xDDCBA987; //0x00000087 0xFFFFFF87

//输出:fun1都是 去除前24位

//fun2:有符号数0xFFFFFF


printf("%x\n",fun1(word4));
printf("%x\n",fun2(word4));


return 0;
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值