1、
#include <stdio.h> #include <math.h> int main(void) { unsigned x, n; printf("test number: "); scanf("%u", &x); printf("move bits : "); scanf("%u", &n); printf("move left : %u | multiply power of 2 : %u\n", x << n, x * (unsigned)pow(2, n)); printf("move right : %u | devide power of 2 : %u\n", x >> n, x / (unsigned)pow(2, n)); return 0; }
2、
#include <stdio.h>
#include <math.h>
int main(void)
{
unsigned x, n;
puts("please input the test number and move bits.");
printf("test number = "); scanf("%u", &x);
printf("move bits = "); scanf("%u", &n);
(x << n) == x * (unsigned)pow(2, n) ? printf("equally\n") : printf("unequally\n");
(x >> n) == x / (unsigned)pow(2, n) ? printf("equally\n") : printf("uneauqlly\n");
return 0;
}
3、
#include <stdio.h> int main(void) { unsigned x, n; puts("please input the test number and move bits."); printf("x = "); scanf("%u", &x); printf("n = "); scanf("%u", &n); unsigned left, vleft = x; left = x << n; int i; for(i = 1; i <= n; i++) { vleft *= 2; } left == vleft ? printf("equally\n") : printf("unequally\n"); unsigned right, vright = x; right = x >> n; for(i = 1; i <= n; i++) { vright /= 2; } right == vright ? printf("equqlly\n") : printf("unequally\n"); return 0; }
原文:https://www.cnblogs.com/liujiaxin2018/p/14792717.html