4: BASIC Stamp Architecture – REV, &, |
BASIC Stamp Programming Manual 2.0c
•
www.parallaxinc.com
•
Page 73
value right n number of times has the same effect as dividing that number
by 2 to the n
th
power. For instance 100 >> 3 (shift the bits of the decimal
number 100 right 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 right Idx places.
NEXT
The Reverse operator (REV) returns a reversed (mirrored) copy of a
specified number of bits of a value, starting with the rightmost bit (lsb).
For instance, %10101101 REV 4 would return %1011, a mirror image of the
first four bits of the value. Example:
DEBUG BIN ? %11001011 REV 4 ' Mirror 1st 4 bits (%1101)
The And operator (&) returns the bitwise AND of two values. Each bit of
the values is subject to the following logic:
0 AND 0 = 0
0 AND 1 = 0
1 AND 0 = 0
1 AND 1 = 1
The result returned by & will contain 1s in only those bit positions in
which both input values contain 1s. Example:
SYMBOL Value1 = B0
SYMBOL Value2 = B1
SYMBOL Result = B2
Value1 = %00001111
Value2 = %10101101
Result = Value1 & Value2
DEBUG %Result ' Show AND result (%00001101)
-- or --
DEBUG BIN ? %00001111 & %10101101 ' Show AND result (%00001101)
The OR operator (|) returns the bitwise OR of two values. Each bit of the
values is subject to the following logic:
2
e
2
sx
2
p
2
2
e
2
sx
2
p
2
1
R
EVERSE
: REV
A
ND
: &
O
R
: |
1
2
e
2
sx
2
p
2
1
2
e
2
sx
2
p
2
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...