有没有在C#中XNOR(逻辑双条件)运算符? [英] Is there XNOR (Logical biconditional) operator in C#?
问题描述
我是新的C#和找不到 XNOR 运营商提供该真值表:
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
有没有这个特定的运算?或者,我需要用!(A ^ B)?
Is there a specific operator for this? Or I need to use !(A^B)?
推荐答案
同或仅仅是针对布尔平等;使用 A ==乙
。
XNOR is simply equality on booleans; use A == B
.
这是错过一件容易的事情,因为平等是不是普遍适用于布尔值。而且有语言的地方不一定会工作。例如,在C,任何非零标值视为真,所以两个真的值可以是相等的。但问题是标签 C#,其中有应我们说,乖巧的布尔值。
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.
另请注意,这并不能概括位操作,您希望 0×1234 XNOR 0x5678的== 0xFFFFBBB3
(假设32位)。对于这一点,你需要从其他业务建立起来,像〜(A ^ B)
。 (注:!〜
,而不是
)
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(逻辑双条件)运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!