EasyManua.ls Logo

Parallax BASIC Stamp 2e - Digit (DIG); Shift Left; Shift Right

Default Icon
353 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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
DIGIT
: DIG
SHIFT LEFT: <<
S
HIFT RIGHT: >>

Table of Contents

Related product manuals