Specifications
BASIC Stamp II
Page 234 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
Integer Math
The BS2 performs all math operations by the rules of positive integer
math. That is, it handles only whole numbers, and drops any fractional
portions from the results of computations. Although the BS2 can inter-
pret two’s complement negative numbers correctly in Debug and Serout
instructions using modifiers like SDEC (for signed decimal), in calcu-
lations it assumes that all values are positive. This yields correct re-
sults with two’s complement negative numbers for addition, subtrac-
tion, and multiplication, but not for division.
This subject is a bit too large to cover here. If you understood the pre-
ceding paragraph, great. If you didn’t, but you understand that han-
dling negative numbers requires a bit more planning (and probably
should be avoided when possible), good. And if you didn’t understand
the preceding paragraph at all, you might want to do some supple-
mental reading on computer-oriented math.
Unary and Binary Operators
In a previous section we discussed the operators you’re already famil-
iar with: +, - ,* and /. These operators all work on two values, as in 1 +
3 or 26*144. The values that operators process are referred to as argu-
ments. So we say that these operators take two arguments.
The minus sign (-) can also be used with a single argument, as in -4.
Now we can fight about whether that’s really shorthand for 0-4 and
therefore does have two arguments, or we can say that - has two roles:
as a subtraction operator that takes two arguments, and as a negation
operator that takes one. Operators that take one argument are called
unary operators and those that take two are called binary operators.
Please note that the term “binary operator” has nothing to do with
binary numbers—it’s just an inconvenient coincidence that the same
word, meaning ‘involving two things’ is used in both cases.
In classifying the BS2’s math and logic operators, we divide them into
two types: unary and binary. Remember the previous discussion of
operator precedence? Unary operators take precedence over binary—
the unary operation is always performed first. For example SQR is the
unary operator for square root. In the expression 10 - SQR 16, the BS2
first takes the square root of 16, then subtracts it from 10.










