C# Bitwise Operator With Ints

落爺英雄遲暮 提交于 2019-12-02 07:27:16
Joe

It's comparing the bits in each value. It returns any bits that are set in both numbers.

In your example:

    3:  0011
    1:  0001

3 & 1:  0001

This checks whether x and y both have at least one common bit set. In the case of your example this would be the true.

driis
if ((x & y) != 0)

This would typically be used to determine whether the value x has a specific bit-flag (y) set. The AND operator returns an integer with only those bits set that are set in both operands.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!