什么是^ =运算符? [英] What is the ^= operator?

查看:76
本文介绍了什么是^ =运算符?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在SO上遇到了一个答案,其中的一个代码示例(以我所认为的Java)使用了一个我从未见过的运算符: ^ = .我搜索了google和SO,却无法在其他任何地方找到它,当我尝试使用java对其进行测试时,eclipse变得疯狂了.我不确定这只是答案中的错字.这个算子是什么?它有名字吗?它是来自什么语言或使用的是什么语言?

I just came across an answer here on SO where a code example (in what I thought was java) used an operator I have never seen before: ^=. I searched google and SO and haven't been able to find it anywhere else and when I tried to test it out using java, eclipse went crazy. Maybe it was just a typo in the answer, I'm not sure. What is this operator? Does it have a name? What language is it from or used in?

推荐答案

这是C/C ++/C#/Java/Javascript/Perl/PHP/Pike按位XOR赋值运算符.

This is the C/C++/C#/Java/Javascript/Perl/PHP/Pike bitwise XOR assignment operator.

当且仅当涉及的两个操作数之一为true时,XOR(异或)条件语句的结果为true.

An XOR (exclusive or) conditional statement evaluates to true if and only if one of the two operands involved is true.

示例:

0 ^ 0 = false
1 ^ 0 = true
0 ^ 1 = true
1 ^ 1 = false //Regular OR would evaluate this as true

以与使用 + = -= * = /= 等相同的方式..此运算符可以与等号结合使用,以在完成操作时进行赋值.

In the same way that you can use += -= *= /= etc... this operator can be combined with an equals sign to perform assignment upon completion.

x += 1; //Same as x = x + 1;
t ^= f; //Same as t = t ^ f;

boolean a = false;
boolean b = true;
a ^= b; //a now evaluates to true;

请参见 Java运算符.

这篇关于什么是^ =运算符?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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