---
title: "Operators"
description: "TapHome script operators: + - * /, =, \u003c\u003e, \u0026, |, ^, \u003c\u003c, \u003e\u003e, AND, OR, XOR, !, precedence in 10 levels, why (a \u0026 1) \u003e 0 needs parentheses, short-circuit AND and OR, Excel BITAND equivalents."
url: "https://taphome.com/en/docs/script/operators/"
language: en
lastmod: 2026-11-06
generator: hugo
ai:
  topics: ["scripting-language","operators","expressions","bit-operations"]
  questions: ["What arithmetic and logical operators are available?","Why does a \u0026 1 \u003e 0 give a wrong result?","Does AND evaluate both sides?","How do I write NOT, modulo or power in a TapHome script?","What is the Excel equivalent of the TapHome bit operators?"]
---

# Operators

Operators of the TapHome script language: arithmetic, comparison, bitwise and logical operators, their 10 precedence levels, the a & 1 > 0 trap, short-circuit evaluation and Excel equivalents.

Last updated: 2026-11-06

Operators in the TapHome script language combine values into expressions: arithmetic, comparison, bitwise and logical operators, plus assignment. They are evaluated in 10 precedence levels, from `*` and `/` down to `OR`, and parentheses override the order. Bitwise operators bind looser than comparisons, so `a & 1 > 0` means `a & (1 > 0)`; always write `(a & 1) > 0`. `AND` and `OR` evaluate the right side only when the left side does not decide the result, and the bit operators have Excel equivalents such as `BITAND`.

## Operator list

The script language has arithmetic, comparison, bitwise and logical operators:

| Group | Operators | Example |
|---|---|---|
| Unary | `-` (negation), `+`, `!` (logical NOT) | `!IsRaining` |
| Multiplicative | `*`, `/` | `(20.5 + 9.5) / 2` is `15` |
| Additive | `+`, `-` | `"T=" + Te` joins text |
| Shift | `<<`, `>>` | `8 << 2` is `32` |
| Relational | `<`, `<=`, `>`, `>=` | `Te > 25` |
| Equality | `=` (equal), `<>` or `!=` (not equal) | `Mode <> 2` |
| Bitwise AND | `&` | `3 & 1` is `1` |
| Bitwise OR, XOR | `\|`, `^` | `2 \| 1` is `3` |
| Logical | `AND`, `XOR`, `OR` | `Te > 25 AND Hu > 60` |
| Assignment | `:=` and the compound forms `+=`, `-=`, `*=`, `/=`, `<<=`, `>>=`, `&=`, `\|=`, `^=` | `x += 1` |

`XOR` on two numbers is a bitwise XOR: `5 XOR 1` is `4`. On `TRUE` and `FALSE` it is the logical XOR.

The language has no `NOT`, `==`, `%`, `**`, `&&` or `||`. Use `!`, `=`, [`MOD`](https://taphome.com/en/docs/script/mathematical-functions/#mod), [`POWER`](https://taphome.com/en/docs/script/mathematical-functions/#power), `AND` and `OR`. `1 == 1` fails with `Wrong number of literals and operators in expression`, `NOT x` with `Unknown variable or constant 'NOT'`.

## Precedence

Operators are evaluated in this order, from the highest precedence to the lowest. Operators of the same level are evaluated from left to right; parentheses `( )` override the order.

1. `*` `/`
2. `+` `-`
3. `<<` `>>`
4. `<` `<=` `>` `>=`
5. `=` `<>` `!=`
6. `&`
7. `|` `^`
8. `AND`
9. `XOR`
10. `OR`

> [!WARNING]
> Unlike C or JavaScript, the bitwise operators bind tighter than `AND` and `OR` but looser than the comparisons. `a & 1 > 0` means `a & (1 > 0)`. Always write `(a & 1) > 0`.

```taphome
# flags holds the value 2
VAR flags := 2;
# the comparison is evaluated first
flags & 2 > 0;
# Result: 0, read as flags & (2 > 0), which is flags & 1
# parentheses test the bit first
(flags & 2) > 0;
# Result: TRUE
```

A compound assignment has the precedence of its operation: `x -= a - b` is evaluated as `(x -= a) - b` and `x *= 1 + 2` as `(x *= 1) + 2`. Put the right side in parentheses:

```taphome
VAR total := 10;
total -= (a - b);
```

## Short-circuit evaluation

`AND` and `OR` evaluate the right side only when the left side does not decide the result yet. `XOR` always evaluates both sides. A condition can therefore protect the expression next to it:

```taphome
va2 <> 0 AND va1 / va2 > 1;
# Result: FALSE when va2 is 0, without the Division by zero error
```

The right side is not evaluated when `va2` is `0`. The same protection for a value is [`IF`](https://taphome.com/en/docs/script/basics/#if), which evaluates only the selected branch.

## Excel equivalents

The bit operators correspond to these Excel and Google Sheets functions:

| TapHome | Excel, Google Sheets | Example |
|---|---|---|
| `a & b` | `BITAND(a, b)` | `3 & 1` is `1` |
| `a \| b` | `BITOR(a, b)` | `2 \| 1` is `3` |
| `a ^ b` | `BITXOR(a, b)` | `6 ^ 3` is `5` |
| `a << n` | `BITLSHIFT(a, n)` | `8 << 2` is `32` |
| `a >> n` | `BITRSHIFT(a, n)` | `32 >> 2` is `8` |

> [!NOTE]
> In Excel `^` is a power; in TapHome it is the bitwise XOR. Use [`POWER`](https://taphome.com/en/docs/script/mathematical-functions/#power) for powers. `IF`, `AND`, `OR` and `MOD` have the same meaning in both, but in TapHome `AND` and `OR` are operators placed between the operands.

See the example of bit operations in Google Sheets: [https://docs.google.com/spreadsheets/d/1hF5FMpGMJbgYh-YLwWrq2n186_ATyGyLUb689__IhLY/edit?usp=sharing](https://docs.google.com/spreadsheets/d/1hF5FMpGMJbgYh-YLwWrq2n186_ATyGyLUb689__IhLY/edit?usp=sharing), or try the interactive tool at [http://bitwisecmd.com/](http://bitwisecmd.com/). Functions that read and write single bits and bytes are on [Bit operations](https://taphome.com/en/docs/script/bit-operations/).
