What does the ^ operator do in Java?

前端 未结 17 1750
执念已碎
执念已碎 2020-11-22 03:27

What function does the ^ (caret) operator serve in Java?

When I try this:

int a = 5^n;

...it gives me:

17条回答
  •  广开言路
    2020-11-22 03:35

    That is because you are using the xor operator.

    In java, or just about any other language, ^ is bitwise xor, so of course,

    10 ^ 1 = 11. more info about bitwise operators

    It's interesting how Java and C# don't have a power operator.

提交回复
热议问题