逻辑异或 [英] Logical XOR

查看:76
本文介绍了逻辑异或的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




只是想知道你们如何在C中执行逻辑XOR。

我正在做的那一刻:


!! a!= !! b


,写的速度比以下更快:


(! a&& b)|| (a&&!b)


如果我们把它写成宏,我们将如何寻求

最短的执行时间?


马丁



Just wondering how you all go about performing a logical XOR in C. At
the moment I''m doing:

!!a != !!b

, which is quicker to write than:

(!a && b) || (a && !b)

If we were to write it as a macro, how would we go about seeking the
shortest execution time?

Martin

推荐答案


!! a!= !! b
!!a != !!b



发送帖子后大约三秒钟我意识到我写了这封信:


!a!=!b


Martin


About three seconds after I sent that post I realised I cuda written:

!a != !b

Martin


9月21日上午11:30,Martin Wells< ;战争...... @ eircom.netwrote:
On Sep 21, 11:30 am, Martin Wells <war...@eircom.netwrote:

!! a!= !! b
!!a != !!b



我发了那篇文章大约三秒钟后,我意识到我写了这个问题:


!a!=!b


Martin


About three seconds after I sent that post I realised I cuda written:

!a != !b

Martin



如果a和b总是布尔值(0或1),只需使用

a ^ b

-

Fred

If a and b are always boolean values (0 or 1), just use
a^b
--
Fred



如果a和b总是布尔值(0或1),只需使用

a ^ b
If a and b are always boolean values (0 or 1), just use
a^b



NO方式,你就是这样的天才。


如果我只想要一个按位异或,我会被分类。


Martin

NO WAY, YOU''RE SUCH A GENIUS.

If only I wanted a bitwise XOR, I''d be sorted.

Martin


这篇关于逻辑异或的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆