Operators are special characters which perform operation on operands (values or variable).There are various kind of operators available in Kotlin.
Arithmetic operators are used to perform basic mathematical operations such as addition (+), subtraction (-), multiplication (*), division (/) etc.
Example of Arithmetic Operator
15 5 50 2 0
Relation operator shows the relation and compares between operands. Following are the different relational operators:
Example of Relation Operator
b is greater than a. max = 10
Assignment operator "=" is used to assign a value to another variable. The assignment of value takes from right to left.
Example of Assignment operator
a+=b :25 a-=b :20 a*=b :100 a/=b :20 a%=b :0
Unary operator is used with only single operand. Following are some unary operator given below.
Example of Unary Operator
+a :10 -b :-5 ++a :11 --b :4 !flag :false
Logical operators are used to check conditions between operands. List of logical operators are given below.
Example of Logical Operator
(a>b) && (a>c) :false (a>b) || (a>c) :true !flag :true
In Kotlin, there is not any special bitwise operator. Bitwise operation is done using named function.
Example of Bitwise Operation
a.shl(b): 40 a.shr(b): 2 a.ushr(b:) 2 a.and(b): 2 a.or(b): 10 a.xor(b): 8 a.inv(): -11