^ 运算符在 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
^ operator in java
提问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 empi
回答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.
按照此链接还可以查看运算符优先级。
回答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.
其他一些答案只说它是按位异或,但请注意,如果操作数是布尔类型,它也可以是逻辑异或,根据此来源。