Modulus operator finds the remainer after division of one number by another
b % a => 0
Relational
Operator
Description
Example
==
Checks if values if two operands are equal
a == b => false
!=
Checks if values of two operands are not equal
a != b => true
>
Checks if left operands is greater than the right
a > b => false
<
Checks if left operands is less than the right
a < b => true
>=
Checks if left operands is greater or equal than the right
a >= b => false
<=
Checks if left operands is less or equal than the right
a <= b => true
Logical
Operator
Description
Example
&&
It is called Logical AND operator
(a && b) => false
||
It is called Logical OR Operator
(a || b) => true
!
It is called Logical NOT Operator
!(a && b) => true
Bitwise
Performs bit by bit operation
Operator
Description
Example
&
Binary AND Operator copies a bit to the result if it exists in both operands.
(a & b) => 0000 1100 = 12
|
Binary OR Operator copies a bit if it exists in either operand.
(a | b) => 0011 1101 = 61
^
Binary XOR Operator copies the bit if it is set in one operand but not both.
(a ^ b) => 0011 0001 = 49
~
Binary Ones Complement Operator is unary and has the effect of 'flipping' bits.
(~a) => 1100 0011 = -61
<<
Binary Left Shift Operator. The bit positions of the left operands value is moved left by the number of bits specified by the right operand.
a << 2 => 1111 0000 = 240
>>
Binary Right Shift Operator. The Bit positions of the left operand value is moved right by the number of bits specified by the right operand.
a >> 2 => 1111 = 15
>>>
Shift right zero fill operator. The left operands value is moved right by the number of bits specified by the right operand and shifted values are filled up with zeros.
a >>> 2 => 0000 1111 = 15
Assignments
Operator
Description
Example
=
Simple assignment operator, Assigns values from right side operands to left side operand
c = a + b
+=
Add AND assignment operator, It adds right operand to the left operand and assign the result to left operand
c += a
-=
Subtract AND assignment operator, It subtracts right from the left and assign the result to left operand
c -= a
*=
Multiply AND assignment operator, It multiplies right with the left and assign the result to left operand
c *= a
/=
Divide AND assignment operator, It divides left operand with the right operand and assign the result to left
c /= a
%=
Modulus AND assignment operator, It takes modulus using two operands and assign the result to left operand