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
: >>
Содержание BASIC Stamp 2e
Страница 1: ...BASIC Stamp Programming Manual Version 2 0c...
Страница 30: ...Introduction to the BASIC Stamps Page 28 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 34: ...Quick Start Guide Page 32 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 90: ...BUTTON BASIC Stamp Command Reference Page 88 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 118: ...END BASIC Stamp Command Reference Page 116 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 128: ...FREQOUT BASIC Stamp Command Reference Page 126 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 196: ...NAP BASIC Stamp Command Reference Page 194 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 206: ...OWIN BASIC Stamp Command Reference Page 204 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 214: ...OWOUT BASIC Stamp Command Reference Page 212 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 216: ...PAUSE BASIC Stamp Command Reference Page 214 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 226: ...POLLMODE BASIC Stamp Command Reference Page 224 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 232: ...POLLOUT BASIC Stamp Command Reference Page 230 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 236: ...POLLRUN BASIC Stamp Command Reference Page 234 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 240: ...POLLWAIT BASIC Stamp Command Reference Page 238 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 262: ...RCTIME BASIC Stamp Command Reference Page 260 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 274: ...RUN BASIC Stamp Command Reference Page 272 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 310: ...SEROUT BASIC Stamp Command Reference Page 308 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 324: ...STOP BASIC Stamp Command Reference Page 322 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 340: ...ASCII Chart Page 338 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 342: ...Reserved Words Page 340 BASIC Stamp Programming Manual 2 0b www parallaxinc com...
Страница 346: ...Conversion Formatters Page 344 BASIC Stamp Programming Manual 2 0b www parallaxinc com...