如何& works when int res = num1& num2其中num1和num2是整数类型 [英] How & works when int res=num1 & num2 where num1 and num2 are integer type

查看:129
本文介绍了如何& works when int res = num1& num2其中num1和num2是整数类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



How & works when

int num1=10,num2=9;
int res=num1 & num2; // where num1 and num2 are integers

res = 8的值; 如何工作

推荐答案

& 是按位AND运算符。如果相应的位也在num1 num2中设置,则结果中的每一位都被设置。

The & is a bitwise-AND operator. Each bit in the result is set only if the corresponding bit is also set in both num1 and num2.

以二进制编写数字:

num1           1010 = 10
num2           1001 =  9
------------------------
num1 & num2    1000 =  8

这篇关于如何& works when int res = num1& num2其中num1和num2是整数类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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