What does the ^ operator do in Java?

Asked 2 years ago, Updated 2 years ago, 66 views

What is the work of a operator in Java? For example, if you do an operation such as inta=5^n;

Operator does
When
n is 5, the value is 0
When n is 4, the value is 1
When n is 3, the value is 3

I don't think it's an index, but what is it?

java exponentiation operator

2022-09-22 22:14

1 Answers

Operator

In Java, the operator is a bit operator that performs a XOR (exclusive-or) operation. For example, if you look at the 56 operation,

Operators are 6's
 (decimal) (binary)
     5     =  101
     6     =  110
------------------ ------------------ xor
     3     =  011

Shows the above operations. The operation of xor is Operator that returns true when A and B are different. Returns false if it is.

In the example above, 101 and 110 are calculated and read as decimal numbers If you look at the number 1, it's 1 and 0, so it's 1 If you look at the digit of 10, it's different from 0 to 1 If you look at the digit of 100, it's equal to 1 and 1, so it's 0. So 011 is going to be 3.


2022-09-22 22:14

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.