| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:[求助]位与运算符计算结果问题!多谢!
只看楼主 加入收藏
welldone2006
Rank: 1
等 级:新手上路
帖 子:148
专家分:0
注 册:2006-1-8
收藏
 问题点数:0 回复次数:0 
[求助]位与运算符计算结果问题!多谢!
#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编辑过]

搜索更多相关主题的帖子: 运算符 结果 
2006-02-17 09:53
快速回复:[求助]位与运算符计算结果问题!多谢!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.016826 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved