BASIC stamp manual v2.2
4: BASIC Stamp Architecture – MAX, DIG, <<, >>
BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com • Page 117
SYMBOL value1 = W0
SYMBOL value2 = W1
FOR value1 = 0 TO 100 STEP 10 ' Walk value1 from 0 to 100
value2 = value1 MAX 50 ' Use MAX to clamp at 50
DEBUG value2 ' Show "clamped" value
NEXT
-- or --
value VAR Word
FOR value = 0 TO 100 STEP 10 ' Walk value from 0 to 100
DEBUG ? value MAX 50 ' Show value, use MAX clamp at 50
NEXT
The Digit operator (DIG) returns the specified decimal digit of a 16-bit
positive value. Digits are numbered from 0 (the rightmost digit) to 4 (the
leftmost digit of a 16-bit number; 0 to 65535).
Example:
value VAR Word
idx VAR Byte
value = 9742
DEBUG ? value DIG 2 ' Show digit 2 (7)
FOR idx = 4 TO 0
DEBUG ? value DIG idx ' Show digits 0 through 4 (09742)
NEXT
The Shift Left operator (<<) shifts the bits of a value to the left a specified
number of places. Bits shifted off the left end of a number are lost; bits
shifted into the right end of the number are 0s. Shifting the bits of a value
left n number of times has the same effect as multiplying that number by 2
to the n
th
power. For instance 100 << 3 (shift the bits of the decimal number
100 left three places) is equivalent to 100 * 2
3
. Here's an example:
value VAR Word
idx VAR Byte
value = %1111111111111111
FOR idx = 1 TO 16 ' Repeat with idx = 1 to 16
DEBUG BIN16 ? value << idx ' Shift value left idx places
NEXT
The Shift Right operator (>>) shifts the bits of a value to the right a
specified number of places. Bits shifted off the right end of a number are
DIGIT: DIG
S
HIFT LEFT: <<
S
HIFT RIGHT: >>
All
2
1
All
2
All
2
All
2