Issue
I’m writing a simple program and one of my first steps involves raising a number by 3.
public class ASum {
public static void main(String[] args) {
System.out.println(0 ^ 3);
}
}
Shouldn’t 0 ^ 3
be 0?
On printout 0 ^ 3 yields 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.
Answered By - Patricia
Answer Checked By - Gilberto Lyons (JavaFixing Admin)