Operators
Solidity supports the following types of operators

  • Arithmetic Operators
  • Assignment Operators
  • Relational Operators
  • Logical Operators
  • Ternary Operator
  • Bitwise Operators
Arithmetic Operators
Arithmetic operators are used to perform arithmetic or mathematical operations

Operation Operator Symbol
Addition+
Subtraction -
Multiplication *
Division /
Increment ++ (add 1)
Decrement — (subtract 1)
Modulus % (x % y gives the remainder of the integer division of x by y)
Exponent ** (p**q is p to the power of q)
Assignment Operators
Assignment operators shorten the code for the assignment of a value to a variable

Operation Operator Symbol
Assignment =
Add assignment +=
Subtract assignment -=
Multiply assignment *=
Divide Assignment /=
Modulus Assignment %=
Relational Operators
Relational operators are the ones you will use in your conditions to compare two Data values or results

Operator Symbol Operator Details
Assignment =
== (equal) returns true if two values are equal, false otherwise. IT’S TWO EQUAL SIGNS!!! The single equal sign is the operator used to assign a value to a variable, don’t confuse them!
!= (not equal) returns true if two values are not equal, false otherwise.
> (greater than) returns true if the left value is greater than the right value, false otherwise.
>= (greater than or equal to) returns true if the left value is greater than or equal to the right value, false otherwise.
< (less than) returns true if the left value is less than the right value, false otherwise.
<= (less than or equal to) returns true if the left value is less than or equal to the right value, false otherwise.
Logical Operators
Logical operators are used to combine two or more conditions or Boolean results

Operator Symbol Operator Details
&& (logical AND) returns true if both conditions are true, returns false otherwise.
|| (logical OR) returns true if at least one condition is true, returns false otherwise.
! (logical NOT) returns true if the condition is false and returns false if the condition is true.
Ternary Operators
Ternary operators is a shortcut to deal with simple if / else conditions. Syntax:

condition ? valueIfConditionIsTrue : valueIfConditionIsFalse
Bitwise Operators
Bitwise operators work directly on bit to perform bit-level operations, with 0 and 1

Operator Symbol Operator Details
& (bitwise AND) performs boolean AND operation on each bit of integer argument.
| (bitwise OR) performs boolean OR operation on each bit of integer argument.
^ (bitwise XOR = Exclusive OR) performs boolean exclusive OR operation on each bit of integer argument.
~ (bitwise NOT) performs boolean NOT operation on each bit of integer argument.
<< (left shift) moves all bits of the first operand to the left by the number of places specified by the second operand.
>> (right shift) moves all bits of the first operand to the right by the number of places specified by the second operand.