关于按位运算符的问题 [英] Question about bitwise operators
问题描述
由于一些奇怪的原因,我认为以下会给我一个价值
168,而不是166.我的理由是678 - 255 - 255 = 168.
>
#include< stdio.h>
int main(无效){
unsigned long a = 678;
unsigned long ff = 255;
unsigned long c = a& ff;
printf(值为:%u \ n,c);
返回0;
}
价值是:166
$
我在这里缺少什么?
提前致谢
Chad
For some strange reason, I thought the following would give me a value
of 168, not 166. My reasoning was that 678 - 255 - 255 = 168.
#include <stdio.h>
int main(void) {
unsigned long a = 678;
unsigned long ff = 255;
unsigned long c = a & ff;
printf("The value is: %u \n", c);
return 0;
}
The value is: 166
$
What am I missing here?
Thanks in advance
Chad
推荐答案
我在这里缺少什么?
提前致谢
Chad
What am I missing here?
Thanks in advance
Chad
Chad写道:
由于某些奇怪的原因,我认为下面的内容会给我一个168的值,而不是166。推理是678 - 255 - 255 = 168。
For some strange reason, I thought the following would give me a value
of 168, not 166. My reasoning was that 678 - 255 - 255 = 168.
用256代替它。
678是0x2a6
0xa6是166
-
pete
Try it with 256 instead.
678 is 0x2a6
0xa6 is 166
--
pete
Chad写道:
由于一些奇怪的原因,我认为以下会给我一个168的价值,而不是166.我的理由是678 - 255 - 255 = 168.
#include< stdio.h>
int main(void){
unsigned long a = 678;
unsigned long ff = 255;
unsigned long c = a& ff;
1010100110(678)
0011111111(255)
----------和
0010100110(166)
printf(值为:%u \ n,c);
返回0;
}
值为:166
For some strange reason, I thought the following would give me a value
of 168, not 166. My reasoning was that 678 - 255 - 255 = 168.
#include <stdio.h>
int main(void) {
unsigned long a = 678;
unsigned long ff = 255;
unsigned long c = a & ff;
1010100110 (678)
0011111111 (255)
---------- AND
0010100110 (166)
printf("The value is: %u \n", c);
return 0;
}
The value is: 166
这篇关于关于按位运算符的问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!