Java equivalent of the ^ ‘operator’ [duplicate]

This question already has an answer here:

Hello there Stack overflow.

I was working through some exercises to hopefully get better at Java, and I ended up needing the ‘^’ operator and then realising it works different in Java.

  • Normally 31^2 would be 961.
  • In Java 31^2 brings us to 29 because in java ^ is a Binary XOR Operator copies the bit if it is set in one operand but not both.

My question is how can i do 31^2=961 in Java (not 31*31), I seem to be unable to find this answer online, is it even possible?

Thanks in advance.