Specifications

BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 281
2
Demo Program
This program uses Lookdown to determine the number of decimal dig-
its in a number. The reasoning is that numbers less than 10 have one
digit; greater than or equal to 10 but less than 100 have two; greater
than or equal to 100 but less than 1000 have three; greater than or equal
to 1000 but less than 10000 have four; and greater than or equal to
10000 but less than 65535 (the largest number we can represent in 16-
bit math) have five. There are two loopholes that we have to plug: (1)
The number 0 does not have zero digits, and (2) The number 65535 has
five digits.
To ensure that 0 is accorded one-digit status, we just put 0 at the begin-
ning of the Lookdown list. Since 0 is not less than 0, an input of 0 re-
sults in 1 as it should. At the other end of the scale, 65535 is not less
than 65535, so Lookdown will end without writing to the result vari-
able, numDig. To ensure that an input of 65535 returns 5 in numDig,
we just put 5 into numDig beforehand.
i var word ' Variable (0-65535).
numDig var nib ' Variable (0-15) to hold # of digits.
for i = 0 to 1000 step 8
numDig = 5 ' If no 'true' in list, must be 65535.
LOOKDOWN i,<[0,10,100,1000,10000,65535],numDig
debug "i= ", rep " "\(5-numdig) ,dec i,tab,"digits=", dec numdig,cr
pause 200
next