4: BASIC Stamp Architecture – Number Representations
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 59
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
everyday decimal (base-10) system. However, you may also use
hexadecimal (base-16; also called hex) or binary (base-2).
Since the symbols used in decimal, hex and binary numbers overlap (e.g.,
1 and 0 are used by all; 0 through 9 apply to both decimal and hex) the
editor software needs prefixes to tell the numbering systems apart, as
shown below:
99 Decimal (no prefix)
$1A6 Hex
%1101 Binary
The BASIC Stamp also automatically converts quoted text into ASCII
codes, and allows you to apply names (symbols) to constants from any of
the numbering systems. For example:
SYMBOL LetterA = "A" ' ASCII code for A (65).
SYMBOL Cheers = 3
SYMBOL Hex128 = $80
SYMBOL FewBits = %1101
-- or --
LetterA CON "A" ' ASCII code for A (65).
Cheers CON 3
Hex128 CON $80
FewBits CON %1101
For more information on constants, see the section "Constants and
Compile-Time Expressions", above.
2
2
2
2
2
2
RUNTIME MATH AND LOGIC.
NUMBER REPRESENTATIONS.