C# Bitwise Operator With Ints

后端 未结 3 1745
没有蜡笔的小新
没有蜡笔的小新 2021-01-25 09:00

What does this expression actually mean??

Note - the x and y vars are just sample values.

int x = 3; 
int y = 1; 

if ((x & y) !=0)

3条回答
  •  星月不相逢
    2021-01-25 09:26

    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
    

提交回复
热议问题