源码:
# include <stdio.h>
int main()
{
unsigned a, b, c, d;
int n;
a = 64;
n = 2;
/* 将操作数a右移(6-n)位 */
b = a >> (6-n);
printf("b = %d/n", b); // 00000000 00000100 =4
/* 将操作数a左移n位 */
c = a << n;
printf("c = %d/n", c); // 00000001 00000000 =256
/* 对操作数a进行的混合位运算 */
d = (a >> (n-1)) | (a << (n+1)); // 00000000 00100000
printf("d = %d/n", d); // 00000010 00000000
return 0; // 00000010 00100000 =32+512=544
}
C_移位运算
最新推荐文章于 2024-04-27 12:42:02 发布