**Balfour**BSc

Jamie **Balfour** BSc

Full stack developer

An operator is similar to a mathematical or boolean operator. Operators can be used for arithmetic (mathematical operator) or for comparison (boolean operator).

There are a collection of mathematical operators that perform different tasks. The expressions used to represent such operators are shown in the following table, along with an example of each.

Name | Description | Operator Code | Example | Result |
---|---|---|---|---|

Addition | Simply used to add two numbers together. | `+` |
`5 + 10` |
15 |

Subtract | Used to subtract the second number from the first | `-` |
`10 - 5` |
5 |

Multiply | Used to multiply two numbers | `*` |
`7 * 4` |
28 |

Divide | Used to divide the first number by the second number and return a floating point number | `/` |
`50 / 7` |
7.14... |

Used to divide the first number by the second number and return an integer result | `\` |
`50 / 7` |
7 | |

Raise | Raise a number to another number in the same way as
the mathematical representation x^{y} |
`^` |
`2^7` |
128 |

Modulus | Used to get the remainder of a division as an integer. | `mod` |
`5 mod 4` |
1 |

These operations can be used to return a result as an integer or floating point number.

A boolean operation can be used to return a boolean value (`True`

or `False`

). The table below specifies all of these available in VB.NET:

Name | Description | Operator Code | Example (of truth) |
---|---|---|---|

Greater than | True if the first expression is greater than the second expression | > | 7 > 4 |

Less than | True if the first expression is less than the second expression | < | 7 < 16 |

Greater than or equal to | True if the first expression is greater than or equal to the second expression | >= | 17 >= 16 |

Less than or equal to | True if the first expression is less than or equal to the second expression | <= | 16 <= 16 |

Equal to | True if both expressions are equal (in VB.NET this works also for strings) | = | 16 = 16 |

Not equal | True if both expressions are not equal (again, works with strings in VB.NET) | <> | 16 <> 7 |

The results of these operations can be placed in a boolean variable as shown in the following sample:

VB.NET

Dim a As Integer = 5 Dim b As Integer = 9 Dim c As Integer c = a + b - 7 Dim result As Boolean result = c > a MsgBox(result)

The above sample should return `True`

through the use of a message
box.

Boolean logic also uses other operators. These can also be represented in VB.NET and are also known as bitwise operators. Formal logic and specification defines the way these work and VB.NET contains expressions that form statements like the following can be constructed in VB.NET:

x = (a ∧ b) ⊕ (c ∨ d)

The above expression will evaluate true when *a* and *b* are both false and either *c* or *d *are
true or when *a* and *b* are both true and both *c* and *d* are false due to the ⊕ operator.

The following table shows these operators.

Name | Description | Logical symbol | Operator code | Example (of truth) |
---|---|---|---|---|

And | Logical conjunction, true when both expressions are true. |
∧ | `And` |
`True And True` |

Or | Logical disjunction, true when either expressions are true. |
∨ | `Or` |
`True Or False` |

Not | Logical negation, returns true when given a false expression. |
¬ | `Not` |
`Not(False)` |

Exclusive or | Returns true when either expression is true, but not when both are true. |
⊕ | `Xor` |
`True Xor False` |

And also | Short-circuit logical and, true when both expressions are true. |
∧ | `AndAlso` |
`True AndAlso True` |

Or else | Short-circuit logical or, true when either expression is true. |
∨ | `OrElse` |
`True OrElse False` |

The following is a truth table that represents each of the operators shown above for some P and some Q.

P | Q | ¬P | P∧Q | P∨Q | P⊕Q | P AndAlso Q | P OrElse Q |
---|---|---|---|---|---|---|---|

T | T | F | T | T | F | T | T |

T | F | F | F | T | T | F | T |

F | T | T | F | T | T | F | T |

F | F | T | F | F | F | F | F |

Short-circuit logic is logic which saves time. Basically, the `AndAlso`

and `OrElse`

operators work exactly
like the And and the Or operators, but the difference is that they
follow a system where the code breaks when the first expression
to evaluate false (for `AndAlso`

) or true (for ` OrElse`

) occurs. This is shown here:

True And False And True And True And True

This will return False, as shown by the second expression - but
the program will check every expression anyway. With `AndAlso`

it will get to the first False expression (the second expression)
and return False.

The opposite happens with `OrElse`

. The following
example shows this:

False Or True Or True Or False Or False

This will return True, as shown by the second expression - but
the program will check every expression anyway. With `OrElse`

it will get to the first True expression (the second expression)
and return True.

They are very easy way to save system resources.

Welcome!

Welcome to my website. My name is Jamie Balfour and I'm
a computer scientist. My website focuses on me but I also write
articles and reviews related to technology and
tutorials designed to help you learn things I know.

Site news

I'm working on some cool new projects at the moment. I will announce more in my blog.

@jamiebalfour04

ZPE 1.6.7 is the third big instalment of ZPE in a row! Many new features have already been added including this bea… https://t.co/GiwYExN0Mh 1 day ago |

Retweet @ClintFalin: i’m not sure what you’re doing but i love you and just want to be involved.
(1momjourney2fit on IG…4 days ago |

Retweet @pressgazette: Culture Secretary refuses to rule out levy on tech giants to fund public interest journalism
https://t.co/e3oWoM4VxL http…4 days ago |

4 days ago |

I'm very proud to say that ZPE 1.6.6 is now available and it's one of the biggest updates to date - it brings a wea… https://t.co/9zwHaQBzQI 4 days ago |

Get in touch