[求助]位与运算符计算结果问题!多谢!
#include <stdio.h>main()
{
unsigned char word[3];
unsigned char temp;
int i,j,tmp;
word[0]=7;/*二进制的0111*/
word[1]=2;/*二进制的0010*/
word[2]=1;/*二进制的0001*/
word[3]=14;/*二进制的1110*/
for(i=0;i<4;i++)
printf("%d,%d\n",word[i],~word[i]);
for(i=0;i<4;i++)
{ temp=~word[i];
switch(i)
{case 0: tmp=temp&word[1]&word[2]&word[3];printf("0=%d\n",tmp);break;
case 1: tmp=word[0]&temp&word[2]&word[3];printf("1=%d\n",tmp);break;//在这里有问题!!!!
case 2: tmp=word[0]&word[1]&temp&word[3];printf("2=%d\n",tmp);break;
case 3: tmp=word[0]&word[1]&word[2]&temp;printf("3=%d\n",tmp);break;
}
if (tmp!=0) break;
};
if (i==0) printf("the lier is a\n");
if (i==1) printf("the lier is b\n");
if (i==2) printf("the lier is c\n");
if (i==3) printf("the lier is d\n");
if(tmp==8) printf("the one is A");
if(tmp==4) printf("the one is B");
if(tmp==2) printf("the one is C");
if(tmp==1) printf("the one is D");
getch();
}
请各位帮忙看看,这段程序在Win-TC运行, 语句case 1: tmp=word[0]&temp&word[2]&word[3];printf("1=%d\n",tmp);break;竟然输出的是tmp=1,而在VC6.0下这句话输出的是tmp=0。我百思不得其解,请问这是为什么?多谢!!!!
[此贴子已经被作者于2006-2-17 9:55:23编辑过]