朴灿烈朴宥拉逛街综艺:if(110&101)是真是假;if(110&110) 是真是假

来源:百度文库 编辑:中科新闻网 时间:2024/05/13 14:53:59

& 是 二进制 按位 “与”(按位乘)运算。
1&0=0,1&1=1,0&0=0。
“与”完看是不是全是0,不是全0则为真,否则为假。

用c程序算一下也知真假:
#include <stdio.h>
#include <stdlib.h>
main ()
{
if (110 & 101) {
printf("110 & 101 is true\n");
} else {printf("110 & 101 is false\n");}

if(110 & 110) {
printf("110 & 110 is true\n");
} else {printf("110 & 110 is false\n");}

exit(0);
}

-------------------
结果:
110 & 101 is true
110 & 110 is true

把110,101分别化为二进制,然后利用1&0=0,1&1=1,的原则,&完看是不是全是0,是则为假,不是0则为真!

1101110&1100101=1100100 TRUE
1101110&1101110=1101110 TRUE