^ 运算符在 Java 中

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/460542/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-11 14:54:33  来源:igfitidea点击:

^ operator in java

javaoperators

提问by Warrior

Can anyone explain the use of ^ operator in java with some examples?

任何人都可以通过一些例子来解释 ^ 运算符在 Java 中的使用吗?

采纳答案by Cody Brocious

This is the same as ^ in most languages, just an XOR.

这与大多数语言中的 ^ 相同,只是一个 XOR。

false ^ false == false
true ^ false == true
false ^ true == true
true ^ true == false 

回答by Zach Scrivena

That's the bitwise exclusive OR operation. Check out the Bitwise and Bit Shift Operators sectionof the Java tutorialsfor more information.

这就是按位异或运算。查看Java 教程Bitwise and Bit Shift Operators 部分以获取更多信息。

回答by DonX

In java ^ operator used for bitwise XOR operation.

在java ^ 运算符中用于按位异或运算。

Follow this link to see the operator precedence also.

按照此链接还可以查看运算符优先级。

http://www.uni-bonn.de/~manfear/javaoperators.php

http://www.uni-bonn.de/~manfear/javaoperators.php

回答by Museful

Some of the other answers only say it is a bitwise XOR, but note that it can also be a logical XOR if the operands are of boolean type, according to this source.

其他一些答案只说它是按位异或,但请注意,如果操作数是布尔类型,它也可以是逻辑异或,根据此来源