按位'和;'操作者 [英] bitwise '&' operator

查看:142
本文介绍了按位'和;'操作者的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我缺乏按位有初步的了解'和;'运营商。

  5 = 101
4 = 100

那么,为什么的输出低于如果条件的真正的原因和位 101安培; 100 应的的:

 的#include<&stdio.h中GT;
主要()
{
   如果(5和4)
      的printf(是\\ n);
}


解决方案

5 101

4 100

5和4 不可以 0

  101
100安培;
↓↓↓
100

问题解决✓


澄清

在C,每一个非零值满足如果状态。也就是说,如果你写的:

 如果(-5){
  如果(100){
     //可达code
  }
}

鉴于:

 如果(0){
  destroyTheWorld(); //我们是安全的
}

I am lacking some basic understanding in bitwise '&' operator.

5 = 101
4 = 100

So why the output of the below if condition is true cause and of bits 101 & 100 should be false:

#include <stdio.h>
main()
{
   if(5&4)
      printf("Yes\n");
}

解决方案

5 is 101

4 is 100

5 & 4 is not 0:

101 
100 &
↓↓↓
100

Problem solved ✓


Clarification:

In C, every non-zero value satisfies the if condition. Meaning, if you write:

if(-5) {
  if(100) {
     //Reachable code
  }
}

Whereas:

if(0) {
  destroyTheWorld(); //We are safe
}

这篇关于按位'和;'操作者的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆