#include <stdio.h>
/* Test out using shifting to multiply and divide */
/* Using full 32 bit numbers */
int main(int argc, char **argv) {
int i,x,result;
/* Make sure there are3 command line arguments
(the program name is one, we also want a number) */
if (argc !=2) {
printf("Error - you have to specify a number\n");
exit(1);
}
x = atoi(argv[1]); /* convert first argument to an int */
/* try shifting left */
for (i=0;i<8;i++) {
result = x << i;
printf("%d << %d = %d\n", x,i,result);
}
/* try shifting right */
for (i=0;i<8;i++) {
result = x >> i;
printf("%d >> %d = %d\n", x,i,result);
}
return(0);
}