BASIC Stamp Architecture – DIG, <<, >>
Page 72
•
BASIC Stamp Programming Manual 2.0b
•
www.parallaxinc.com
65535+1 MAX 65535 will result in 0 because of the way fixed-size integers
wrap around.
SYMBOL Value1 = W0
SYMBOL Value2 = W1
FOR Value1= 0 TO 100 STEP 10 ' Walk value of Value1 from 0 to 100.
Value2 = Value1 MAX 50 ' Use MAX to clamp at 50.
DEBUG Value2 ' Show "clamped" value
NEXT
-- or --
Value1 VAR WORD
FOR Value1= 0 TO 100 STEP 10 ' Walk value of Value1 from 0 to 100.
DEBUG ? Value1 MAX 50 ' Show Value1, but use MAX to 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 = 0 TO 4
DEBUG ? Value DIG Idx ' Show digits 0 through 4 of 9742.
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 BIN ? Value << Idx ' Shift Value left Idx places.
NEXT
The Shift Right operator (>>) shifts the bits of a variable to the right a
specified number of places. Bits shifted off the right end of a number are
lost; bits shifted into the left end of the number are 0s. Shifting the bits of a
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
D
IGIT
: DIG
S
HIFT
L
EFT
: <<
S
HIFT
R
IGHT
: >>
Summary of Contents for BASIC Stamp 2e
Page 1: ...BASIC Stamp Programming Manual Version 2 0c...
Page 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Page 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...