BASIC stamp manual v2.2

4: BASIC Stamp Architecture – Number Representations
BASIC Stamp Syntax and Reference Manual 2.2 www.parallax.com Page 97
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 (prefix ‘$’ required)
%1101 ' Binary (prefix ‘%’ required)
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
Binary Coded Decimal (BCD) is a way to encode decimal digits that is
easier to display or manipulate in some devices. Each digit of the decimal
number (0 – 9) requires 4 bits (a nibble) to encode. For this reason, a BCD
byte is always two decimal digits and a BCD word is always four decimal
digits. The BASIC Stamp does not support BCD natively, however,
because of the way that BCD is encoded the BS2 models’ hexadecimal
prefix, and Conversion Formatters can be used as a shortcut for most BCD
input/output operations as long as the digits used do not exceed valid
decimal digits (0 – 9). For example:
BCDValue CON $4096
DEBUG HEX BCDValue
The first line creates a symbol, BCDValue, that contains the binary form of
the hexadecimal value $4096, which means the upper nibble contains the
binary value for the decimal digit 4, the next nibble is 0, the next nibble is 9
1
All
2
HEX TO BCD CONVERSION
All
2