11

我试图找到用 C 语言编写 XNOR 门的最有效方法。

if(VAL1 XNOR VAL2)
{
    BLOCK;
}

有什么建议么?

谢谢。

4

3 回答 3

26

With two operands this is quite simple:

if (val1 == val2)
{
    block;
}
于 2010-06-06T08:13:26.087 回答
7
if(!(val1^val2))
{
    block;
}

编辑:在逻辑运算之外,您可能想要~(val1^val2)准确,但我发现!更清晰。

于 2010-06-06T08:04:10.367 回答
0

Presuming val1 and val2 are to be treated in the normal C logical boolean fashion (non-zero is true), then:

if (!val1 ^ !!val2)
{

}

will do the trick.

于 2010-06-06T08:13:00.863 回答