C#中的位运算。如何将 2 long 转换为 bool 结果?
Bitwise operation in C#. How to convert 2 long's to a bool result?
如何在 C# 中检查“1”是否在“9”中?
long l1 = 1L; // 0001
long l9 = 9L; // 1001
if (l1 & l9) // True (Cannot implicit convert 'long' to 'bool)
{
}
在 JavaScript 中使用“&”是可能的,在 vb 中是 "And",但我不知道我在这里遗漏了什么。
// check if result of binary op is != 0
// that means "contains"
if ((l1 & l9) != 0)
{
...
}
您需要检查运算结果是否不等于0。
编辑
正如@Damien:正确指出,在这种情况下,将更正以检查 0
的不等式,因为如果以某种方式涉及第 63 位,简单的 >0
比较可能会产生误报。
如何在 C# 中检查“1”是否在“9”中?
long l1 = 1L; // 0001
long l9 = 9L; // 1001
if (l1 & l9) // True (Cannot implicit convert 'long' to 'bool)
{
}
在 JavaScript 中使用“&”是可能的,在 vb 中是 "And",但我不知道我在这里遗漏了什么。
// check if result of binary op is != 0
// that means "contains"
if ((l1 & l9) != 0)
{
...
}
您需要检查运算结果是否不等于0。
编辑
正如@Damien:正确指出,在这种情况下,将更正以检查 0
的不等式,因为如果以某种方式涉及第 63 位,简单的 >0
比较可能会产生误报。