Specifications

BASIC Stamp II
Parallax, Inc. • BASIC Stamp Programming Manual 1.8 • Page 237
2
debug SQR 100 ' Display square root of 100 (10).
debug SQR 99 ' Display of square root of 99 (9 due to truncation)
DCD
2
n
-power decoder of a four-bit value. DCD accepts a value from 0 to
15, and returns a 16-bit number with that bit number set to 1. For ex-
ample:
w1 = DCD 12 ' Set bit 12.
debug bin ? w1 ' Display result (%0001000000000000)
NCD
Priority encoder of a 16-bit value. NCD takes a 16-bit value, finds the
highest bit containing a 1 and returns the bit position plus one (1 through
16). If no bit is set—the input value is 0—NCD returns 0. NCD is a fast
way to get an answer to the question “what is the largest power of two
that this value is greater than or equal to?” The answer that NCD re-
turns will be that power, plus one. Example:
w1 = %1101 ' Highest bit set is bit 3.
debug ? NCD w1 ' Show the NCD of w1 (4).
-
Negates a 16-bit number (converts to its two’s complement).
w1 = -99 ' Put -99 (two's complement format) into w1.
debug sdec ? w1 ' Display it on the screen as a signed #.
w1 = ABS w1 ' Now take its absolute value.
debug sdec ? w1 ' Display it on the screen as a signed #.
~
Complements (inverts) the bits of a number. Each bit that contains a 1
is changed to 0 and each bit containing 0 is changed to 1. This process
is also known as a “bitwise NOT.” For example:
b1 = %11110001 ' Store bits in byte b1.
debug bin ? b1 ' Display in binary (%11110001).
b1 = ~ b1 ' Complement b1.
debug bin ? b1 ' Display in binary (%00001110).