- Erlang Tutorial
- Erlang - Home
- Erlang - Overview
- Erlang - Environment
- Erlang - Basic Syntax
- Erlang - Shell
- Erlang - Data Types
- Erlang - Variables
- Erlang - Operators
- Erlang - Loops
- Erlang - Decision Making
- Erlang - Functions
- Erlang - Modules
- Erlang - Recursion
- Erlang - Numbers
- Erlang - Strings
- Erlang - Lists
- Erlang - File I/O
- Erlang - Atoms
- Erlang - Maps
- Erlang - Tuples
- Erlang - Records
- Erlang - Exceptions
- Erlang - Macros
- Erlang - Header Files
- Erlang - Preprocessors
- Erlang - Pattern Matching
- Erlang - Guards
- Erlang - BIFS
- Erlang - Binaries
- Erlang - Funs
- Erlang - Processes
- Erlang - Emails
- Erlang - Databases
- Erlang - Ports
- Erlang - Distributed Programming
- Erlang - OTP
- Erlang - Concurrency
- Erlang - Performance
- Erlang - Drivers
- Erlang - Web Programming

- Erlang Useful Resources
- Erlang - Quick Guide
- Erlang - Useful Resources
- Erlang - Discussion

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

# Erlang - Operators

An operator is a symbol that tells the compiler to perform specific mathematical or logical manipulations.

Erlang has the following type of operators −

- Arithmetic operators
- Relational operators
- Logical operators
- Bitwise operators

## Arithmetic Operators

Erlang language supports the normal Arithmetic operators as any the language. Following are the Arithmetic operators available in Erlang.

Operator | Description | Example |
---|---|---|

+ | Addition of two operands | 1 + 2 will give 3 |

− | Subtracts second operand from the first | 1 - 2 will give -1 |

* | Multiplication of both operands | 2 * 2 will give 4 |

/ | Division of numerator by denominator | 2 / 2 will give 1 |

rem | Remainder of dividing the first number by the second | 3 rem 2 will give 1 |

div | The div component will perform the division and return the integer component. | 3 div 2 will give 1 |

## Relational Operators

The Relational Operators allow the comparison of objects. Following are the relational operators available in Erlang.

Operator | Description | Example |
---|---|---|

== | Tests the equality between two objects | 2 = 2 will give true |

/= | Tests the difference between two objects | 3 /= 2 will give true |

< | Checks to see if the left object is less than the right operand. | 2 < 3 will give true |

=< | Checks to see if the left object is less than or equal to the right operand. | 2 =<3 will give true |

> | Checks to see if the left object is greater than the right operand. | 3 > 2 will give true |

>= | Checks to see if the left object is greater than or equal to the right operand. | 3 >= 2 will give true |

## Logical Operators

These Logical Operators are used to evaluate Boolean expressions. Following are the logical operators available in Erlang.

Operator | Description | Example |
---|---|---|

or | This is the logical “or” operator | true or true will give true |

and | This is the logical “and” operator | True and false will give false |

not | This is the logical “not” operator | not false will give true |

xor | This is the logical exclusive “xor” operator | True xor false will give true |

## Bitwise Operators

Erlang provides four bitwise operators. Following are the bitwise operators available in Erlang.

Sr.No. | Operator & Description |
---|---|

1 |
This is the bitwise “and” operator |

2 |
This is the bitwise “or” operator |

3 |
This is the bitwise “xor” or Exclusive or operator |

4 |
This is the bitwise negation operator |

Following is the truth table showcasing these operators −

p | q | p & q | p | q | p ^ q |
---|---|---|---|---|

0 | 0 | 0 | 0 | 0 |

0 | 1 | 0 | 1 | 1 |

1 | 1 | 1 | 1 | 0 |

1 | 0 | 0 | 1 | 1 |

## Operator Precedence

The following table shows the Operator Precedence for the Erlang operators in order of descending priority together with their associativity. Operator precedence and associativity are used to determine the evaluation order in un-parenthesized expressions.

Operators | Associativity |
---|---|

: | |

# | |

bnot,not | |

/,*,div,rem,band,and | Left associative |

+,-,bor,bxor,or,xor | Left associative |

==,/=,=<,<,>=,> |