Is there XNOR (Logical biconditional) operator in C#?(C# 中是否有 XNOR(逻辑双条件)运算符?)
问题描述
我是 C# 新手,找不到 XNOR 运算符来提供这个真值表:
<上一页>a b a XNOR b----------------T T T对了F T FF F T是否有专门的运营商来做这件事?或者我需要使用 !(A^B)?
XNOR 只是布尔值上的相等;使用 A == B
.
这很容易被忽略,因为相等性通常不应用于布尔值.并且有些语言不一定有效.例如,在 C 中,任何非零标量值都被视为真,因此两个真"值可能不相等.但是问题被标记为 c#,它有,容我们说,表现良好的布尔值.
另请注意,这并不适用于按位运算,您需要 0x1234 XNOR 0x5678 == 0xFFFFBBB3
(假设为 32 位).为此,您需要从其他操作构建,例如 ~(A^B)
.(注意:~
,而不是 !
.)
I'm new to C# and could not find XNOR operator to provide this truth table:
a b a XNOR b ---------------- T T T T F F F T F F F T
Is there a specific operator for this? Or I need to use !(A^B)?
XNOR is simply equality on booleans; use A == B
.
This is an easy thing to miss, since equality isn't commonly applied to booleans. And there are languages where it won't necessarily work. For example, in C, any non-zero scalar value is treated as true, so two "true" values can be unequal. But the question was tagged c#, which has, shall we say, well-behaved booleans.
Note also that this doesn't generalize to bitwise operations, where you want 0x1234 XNOR 0x5678 == 0xFFFFBBB3
(assuming 32 bits). For that, you need to build up from other operations, like ~(A^B)
. (Note: ~
, not !
.)
这篇关于C# 中是否有 XNOR(逻辑双条件)运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!