XOR 和 NOT-EQUAL-TO 有什么区别? [英] What's the difference between XOR and NOT-EQUAL-TO?

查看:29
本文介绍了XOR 和 NOT-EQUAL-TO 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的问题以 Java 为例,但我想它可能适用于所有人.

My question uses Java as an example, but I guess it applies to probably all.

在比较布尔值时,XOR 运算符(Java 中的 ^)和不等于运算符(Java 中的 !=)之间有什么实际区别吗?

Is there any practical difference between the XOR operator (^ in Java) and the not-equal-to operator (!= in Java), when comparing booleans?

我在这里评估了一些东西,但我一直在想(看起来很奇怪,两个东西相等)......并且在网上没有找到任何东西.只是某个论坛上的一次讨论很快就结束了,没有任何结果.

I evaluated things here, but I just kept wondering (seems weird, two things equal)... and didn't find anything on the net. Just one discussion in some forum that ended quickly without any result.

推荐答案

对于布尔值,它们的含义相同——尽管有一个用于 XOR 的复合赋值运算符:

For Boolean values, they mean the same thing - although there's a compound assignment operator for XOR:

x ^= y;

不等式没有等效的复合赋值运算符.

There's no equivalent compound assignment operator for inequality.

至于为什么它们都可用 - XOR not 可用会很奇怪,因为它的工作方式与不等式相同.它应该在逻辑上在那里,所以它是.对于非布尔类型,结果是不同的,因为它是不同的结果类型,但这并不意味着删除 boolean 的 XOR 是有意义的.

As for why they're both available - it would be odd for XOR not to be available just because it works the same way as inequality. It should logically be there, so it is. For non-Boolean types the result is different because it's a different result type, but that doesn't mean it would make sense to remove XOR for boolean.

这篇关于XOR 和 NOT-EQUAL-TO 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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