与整数布尔运算 [英] boolean operations with integers

查看:172
本文介绍了与整数布尔运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这大概是pretty基本...但我似乎并没有得到它:

This is probably pretty basic... but I don't seem to get it:

如何

(2 & 1) = 0
(3 & 1) = 1
(4 & 1) = 0

以上这个模式似乎帮助寻找偶数

This pattern above seems to help find even numbers

(0 | 1) = 1
(1 | 1) = 1
(2 | 1) = 3
(3 | 1) = 4
(4 | 1) = 5
(5 | 1) = 5

我知道如何布尔代数位之间的作品。但我不明白怎么代数与布尔整数(在至少在C#)的作品。

I know how boolean algebra works between bits. But I don't understand how Boolean algebra works with integers (in C# at the least).

先谢谢了。

推荐答案

它工作在C#中以同样的方式,因为它在二进制一样。

It works the same way in C# as it does in binary.

2 | 1 = 3 4 | 1 = 5

要理解这一点,你需要考虑的1,2,3,4二进制重新presentation和5:

To understand this, you need to think about the binary representation of 1,2,3,4,and 5:

010 | 001 = 011 100 | 001 = 101

同样的:

010安培; 001 = 000 011安培; 001 = 001

这篇关于与整数布尔运算的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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