我试图找到用 C 语言编写 XNOR 门的最有效方法。
if(VAL1 XNOR VAL2)
{
BLOCK;
}
有什么建议么?
谢谢。
With two operands this is quite simple:
if (val1 == val2)
{
block;
}
if(!(val1^val2))
{
block;
}
编辑:在逻辑运算之外,您可能想要~(val1^val2)
准确,但我发现!更清晰。
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.