# PBASIC Operators

(See Operator Precedence for details of the sequence in which expression operators are evaluated.)

## Binary and Unary Operators

There are two types of operators in PBASIC, binary operators which require two arguments (such as the addition operator in 2 + 3) and unary operators which require one argument (such as the negate operator in -5). All the PBASIC operators are shown below, grouped under binary operators or unary operators. Click on any operator to see a full description on the Binary Operator or Unary Operator page.

## Notes about the 16-bit workspace

Many of the operator descriptions will say something like "computes (some function) of a 16-bit number." This does not mean that the operator does not work on smaller byte or nibble values, but rather that the computation is done in a 16-bit workspace. If the value is smaller than 16 bits, the BASIC Stamp pads it with leading 0s to make a 16-bit value. If the 16-bit result of a calculation is to be packed into a smaller variable, the higher-order bits are discarded (truncated).

Binary Operators
| • + |  |  | Addition
| • - |  |  | Subtraction
| • * |  |  | Multiplication
| • ** |  |  | Multiply High (Return Upper 16 Bits)
| • */ |  |  | Multiply Middle (Return Middle 16 Bits)
| • / |  |  | Division
| • // |  |  | Modulus (Remainder of Division)
| • MIN |  |  | Limit a Value to Specified Low
| • MAX |  |  | Limit a Value to Specified High
| • DIG |  |  | Return Specified Digit of Number
| • REV |  |  | Reverse Specified Number of Bits
| • << |  |  | Shift Bits Left by Specified Amount
| • >> |  |  | Shift Bits Right by Specified Amount
| • & |  |  | Bitwise AND
| • | |  |  | Bitwise OR
| • ^ |  |  | Bitwise XOR
| • &/ |  |  | Bitwise AND NOT
| • |/ |  |  | Bitwise OR NOT
| • ^/ |  |  | Bitwise XOR NOT
| • AND |  |  | Logical AND
| • OR |  |  | Logical OR
| • XOR |  |  | Logical XOR
| • ATN |  |  | Return Arctangent of Vector
| • HYP |  |  | Return Hypotenuse
Unary Operators
| • ABS |  |  | Return Absolute Value
| • - |  |  | Negate
| • ~ |  |  | Bitwise Inverse
| • DCD |  |  | 2n-power Decoder
| • NCD |  |  | Priority Encoder of 16-bit Value
| • SIN |  |  | Return (signed) Sine Value of Angle
| • COS |  |  | Return (signed) Cosine Value of Angle
| • SQR |  |  | Return Square Root of value
| • NOT |  |  | Logical NOT

Go to Welcome page

BASIC Stamp Help Version 2.5.4

Copyright © Parallax Inc.

8/8/2012