开发者

C: XNOR / Exclusive-Nor gate?

I am trying to fin开发者_如何学运维d the most effective way of writing a XNOR gate in C.

if(VAL1 XNOR VAL2)
{
    BLOCK;
}

Any suggestions?

Thanks.


With two operands this is quite simple:

if (val1 == val2)
{
    block;
}


if(!(val1^val2))
{
    block;
}

edit: outside of logical operations, you'd probably want ~(val1^val2) to be exact, but i find the ! clearer.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜