BASIC stamp manual v2.2

BASIC Stamp Architecture – Number Representations
Page 96 BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com
Now, assuming that you used the constant Cheers wherever your program
needed ‘the number of cheers,’ your upgrade would be done.
On all BS2 models, you can take this idea a step further by defining
constants with expressions; groups of math and/or logic operations that
the editor software solves (evaluates) at compile-time (the time right after
you start the download and before the BASIC Stamp starts running your
program). For example, suppose the “Cheers” program also controls a
pump to fill glasses with champagne. Perhaps the number of glasses to fill
is always twice the number of cheers, minus 1 (another constant):
Cheers CON 5 ' # of cheers
Glasses CON Cheers*2-1 ' # of glasses
As you can see, one constant can be defined in terms of another. That is,
the number glasses depends on the number cheers.
The expressions used to define constants must be kept fairly simple. The
editor software solves them from left to right, and doesn’t allow you to use
parentheses to change the order of evaluation. The operators that are
allowed in constant expressions are shown in Table 4.5.
Operator Symbol Description
+ Add
- Subtract
* Multiply
/ Divide
<< Shift Left
>> Shift Right
& Logical AND
| Logical OR
^ Logical XOR
Table 4.5: Operators allowed in
constant expressions for all BS2
models.
The BASIC Stamp, like any computer, excels at math and logic. However,
being designed for control applications, the BASIC Stamp does math a
little differently than a calculator or spreadsheet program. This section will
help you understand BASIC Stamp numbers, math, and logic.
In your programs, you may express a number in various ways, depending
on how the number will be used and what makes sense to you. By default,
the BASIC Stamp recognizes numbers like 0, 99 or 62145 as being in our
RUN-TIME MATH AND LOGIC.
N
UMBER REPRESENTATIONS.
All
2
All
2
1
A
ll
2