Im writing a simple program and one of my first step involves raising a number by 3.
public class ASum {
public static void main(String[] args) {
findNb(135440716410000L);
}
public static long findNb(long m) {
int n = 0;
System.out.println(0 ^ 3);
return 0;
}
}
On printout 0 ^ 3 returns 3. Like holy cow! 1 ^ 3 returns 2. Somebody help I’m going nuts.
Is ^ the same as the modulus operator?
>Solution :
It is a bitwise exclusive OR operator.
So you represent the numbers with 0s and 1s and an OR is made.
When one operator is 0 it is represented with zeros only so the result is the same as the other operator.