Topic 4_Operators in Java (1) (1)
Topic 4_Operators in Java (1) (1)
These two operators are unary operators, meaning they only operate on a single
operand.
For example:
x = 5;
x = x + 1;
y = x;
Java Assignment Operators
An assignment operator is used for assigning a value to a variable. The most
common assignment operator is =.
0 0 0 0 0 0 1 0 2 0 0 0 0 0 0 1 0 2
0 0 0 0 0 0 1 1 3 1 1 1 1 1 1 0 1 ~2 = -3
0 0 0 0 0 0 1 0 2&3=2
Bit-wise XOR Operator
Bit-wise OR Operator
0 0 0 0 0 0 1 0 2
0 0 0 0 0 0 1 0 2
0 0 0 0 0 0 1 1 3
0 0 0 0 0 0 1 1 3
0 0 0 0 0 0 0 1 2^3=1
0 0 0 0 0 0 1 1 2|3=2
Java Shift Operators
Shift Operators operates on the individual
bits of their operands. It shifts the bits of its
operand either to the left or right.
Right Shift Operator
Operator Description Example
>> Shifts the bits of the x 0 0 0 0 0 1 0 1 5
operand to the right by
(Right Shift) x >> y
the number of position 0 0 0 5 >> 2 = 1
0 0 0 0 1
specified y
<< Shifts the bits of the x
operand to the left by the
(Left Shift) x << y
number of position 0 0 0 0 0 1 0 0 4
specified y
0 0 0 1 0 0 0 0 4 << 2 = 16