I just saw it in a code, so I tried this :
int i = 30;
System.out.println(i^3);
Result is :
29
What is this ? Thanks.
I just saw it in a code, so I tried this :
int i = 30;
System.out.println(i^3);
Result is :
29
What is this ? Thanks.
^
its an exclusove OR operator (XOR).
Its actually bitwise sum % 2.
11110 (30)
00011 (3)
----------
11101 (29)
^
in Java is the XOR operator
XOR stands for a bitwise Exclusive OR. IE:
0 XOR 0 = 0
0 XOR 1 = 1
If the bit's are different (exclusive) then the output is a 1, otherwise a 0.
So following your example:
11110 XOR
00011 =
11101 = 29