/*1、用位操作实现无符号整数的乘法运算,函数原型是unsigned int multiply(unsigned int x, unsigned int y);。例如:(11011)2×(10010)2=((11011)2
unsigned int multiply(unsigned int a,unsigned int b)
{
int c =0,i = 0;
for (;i >=1;//b右移1位
}
else
{
b>>=1;
}
}
return c ;
}
int main ()
{
unsigned int x,y;
printf("Please input x and y value:");
scanf("%u%u",&x,&y);
printf("自动实现:%d*%d=%d\n",x,y,x*y);
printf("函数实现:%d*%d=%d\n",x,y, multiply(x,y));
return 0;
}
/*2、对一个32位无符号整数做循环右移,函数原型是unsigned int rotate_right(unsigned int x, int n);
所谓循环右移就是把低位移出去的部分再补到高位上去,例如rotate_right(0xdeadbeef, 8)的值应该是0xefdeadbe。*/
#include
unsigned int rotate_right(unsigned int x, int n);
int main()
{
unsigned int x;
int n ;
printf("Please input x and n:");
scanf("%u%d",&x,&n);
printf("x:%u\n",rotate_right(x, n));
return 0;
}
unsigned int rotate_right(unsigned int x, int n)
{
for (int i = 0;i > 1;
x = x + 0x80000000;//x+=1> 1;
}
}
return x;
}