请问一些关于char类型数据转换成16进制的问题!! 以及移位操作符~ 拜托了~~~~~
题目是这样的,给出下面的代码,运行,解释output是怎么得出来的charc1=-1,c2=0,c3=1;unsignedcharc4=-1;printf("valuei...
题目是这样的,给出下面的代码,运行,解释output是怎么得出来的
char c1 = -1, c2 = 0, c3 = 1;
unsigned char c4 = -1;
printf("value in c1, c2, c3 and c4 as HEX are: %x %x %x %x\n", c1, c2, c3, c4);
printf("bitwise or %x\n", c1 | c2);
printf("bitwise or unsigned %x\n", c4 | c2);
printf("bitwise and %x\n", c1 & c2);
printf("%d\n", (~c1) + 1);
printf("%x\n", c3 >> 2);
printf("%x\n", c4 << 2);
printf("%x\n", c1 ^ c4);
c1 ^= c2;
c2 ^= c1;
printf("%x\n", c1);
printf("%x\n", c2);
c1 ^= c2;
printf("%x\n", c1);
c1 >>= 2;
printf("%x\n", c1);
结果是这样的:
value in c1, c2, c3 and c4 as HEX are: ffffffff 0 1 ff
bitwise or ffffffff
bitwise or unsigned ff
bitwise and 0
1
0
3fc
ffffff00
ffffffff
ffffffff
0
0
请问那些ffffffff是怎么回事啊~??!?~~~为什么char类型的-1的十六进制是ffffffff呢? 而unsigned char类型的-1的十六进制是ff呢?! 还有左移位右移位的问题~~ 到底是以多少bit为标准呢? 32位吗?? 谢谢大家麻烦帮我看看吧~~ 老师都没教清楚就让我们做~~ 拜托了~啊啊~~ 能帮到我的可以加分~~
谢谢谢谢!!!!!!!! T___T 展开
char c1 = -1, c2 = 0, c3 = 1;
unsigned char c4 = -1;
printf("value in c1, c2, c3 and c4 as HEX are: %x %x %x %x\n", c1, c2, c3, c4);
printf("bitwise or %x\n", c1 | c2);
printf("bitwise or unsigned %x\n", c4 | c2);
printf("bitwise and %x\n", c1 & c2);
printf("%d\n", (~c1) + 1);
printf("%x\n", c3 >> 2);
printf("%x\n", c4 << 2);
printf("%x\n", c1 ^ c4);
c1 ^= c2;
c2 ^= c1;
printf("%x\n", c1);
printf("%x\n", c2);
c1 ^= c2;
printf("%x\n", c1);
c1 >>= 2;
printf("%x\n", c1);
结果是这样的:
value in c1, c2, c3 and c4 as HEX are: ffffffff 0 1 ff
bitwise or ffffffff
bitwise or unsigned ff
bitwise and 0
1
0
3fc
ffffff00
ffffffff
ffffffff
0
0
请问那些ffffffff是怎么回事啊~??!?~~~为什么char类型的-1的十六进制是ffffffff呢? 而unsigned char类型的-1的十六进制是ff呢?! 还有左移位右移位的问题~~ 到底是以多少bit为标准呢? 32位吗?? 谢谢大家麻烦帮我看看吧~~ 老师都没教清楚就让我们做~~ 拜托了~啊啊~~ 能帮到我的可以加分~~
谢谢谢谢!!!!!!!! T___T 展开
1个回答
2009-05-03
展开全部
char c1 = -1, c2 = 0, c3 = 1;
unsigned char c4 = -1;
printf("value in c1, c2, c3 and c4 as HEX are: %x %x %x %x\n", c1, c2, c3, c4);
printf("bitwise or %x\n", c1 | c2);
printf("bitwise or unsigned %x\n", c4 | c2);
printf("bitwise and %x\n", c1 & c2);
printf("%d\n", (~c1) + 1);
printf("%x\n", c3 >> 2);
printf("%x\n", c4 << 2);
printf("%x\n", c1 ^ c4);
c1 ^= c2;
c2 ^= c1;
printf("%x\n", c1);
printf("%x\n", c2);
c1 ^= c2;
printf("%x\n", c1);
c1 >>= 2;
printf("%x\n", c1);
结果是这样的:
value in c1, c2, c3 and c4 as HEX are: ffffffff 0 1 ff
bitwise or ffffffff
bitwise or unsigned ff
bitwise and 0
1
0
3fc
ffffff00
ffffffff
ffffffff
0
0
unsigned char c4 = -1;
printf("value in c1, c2, c3 and c4 as HEX are: %x %x %x %x\n", c1, c2, c3, c4);
printf("bitwise or %x\n", c1 | c2);
printf("bitwise or unsigned %x\n", c4 | c2);
printf("bitwise and %x\n", c1 & c2);
printf("%d\n", (~c1) + 1);
printf("%x\n", c3 >> 2);
printf("%x\n", c4 << 2);
printf("%x\n", c1 ^ c4);
c1 ^= c2;
c2 ^= c1;
printf("%x\n", c1);
printf("%x\n", c2);
c1 ^= c2;
printf("%x\n", c1);
c1 >>= 2;
printf("%x\n", c1);
结果是这样的:
value in c1, c2, c3 and c4 as HEX are: ffffffff 0 1 ff
bitwise or ffffffff
bitwise or unsigned ff
bitwise and 0
1
0
3fc
ffffff00
ffffffff
ffffffff
0
0
参考资料: 书上
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询