(企业面试题1.)输入一个字节内的数(0-255)和移动位数.输出移位结果(要求循环移位)(系统自带的移位都是非循环的)
int number = 0,count = 0;//number表输入的数,count表示移位数
printf("please enter two number:");
scanf("%d%d",&number,&count);
unsigned char a = (char)number;
unsignedchar b = 0;
int x = a<<count;
int y = a>>(8-count);
b = x|y;
printf("%u",b);
(企业面试题2.)定义一个宏,来实现一个整数奇偶比特位的交换,例如:6奇偶比特位交换后的结果是9,如何用宏来实现
#define SWATCH(n) (n&0x55555555)<<1 |( n&0xaaaaaaaa)>>1
int num = 0;
do {
printf("please input a positive number: ");
scanf("%d",&num);
} while (num<0);
printf("%d",SWATCH(num));