在c 中左移也就是所说的逻辑移位,右端补0,
而右移是算数移位,左端补齐的是最高位的符号位。
故负数左移,有可能变成正数,
但负数右移,肯定还是负数。void test()
{
int a = 10;
printf("10 a>>3 %d\n",a>>3);
printf("10 a<<3 %d\n",a<<3);
a = -10;
printf(" -10 a>>3 %d\n",a>>3);
printf(" -10 a>>4 %d\n",a>>4);
printf("-10 a<<3 %d\n",a<<3);
}
void test1()
{
int i = 0x8000000f;
int j = i >> 3;
int k = i << 1;
printf("%d %x\n",i,i);
printf("%d %x\n",j,j);
printf("%d %x\n",k,k);
i = -9;
printf("%d %x\n",i,i);
i = 0xfffffff7;
j = i >> 3;
k = i << 1;
printf("%d %x\n",i,i);
printf("%d %x\n",j,j);
printf("%d %x\n",k,k);
}
void test2()
{
char i = 0x0f;
char j = i >> 3;
char k = i << 1;
printf("%d %x\n",i,i);
printf("%d %x\n",j,j);
printf("%d %x\n",k,k);
i = -9;
printf("%d %x\n",i,i);
i = 0x17;
j = i >> 3;
k = i << 1;
printf("%d %x\n",i,i);
printf("%d %x\n",j,j);
printf("%d %x\n",k,k);
i = 5;
j = i >> 3;
k = i << 1;
printf("%d %x\n",i,i);
printf("%d %x\n",j,j);
printf("%d %x\n",k,k);
}