R
: REV
EVERSE
2
2
e
A
: &
ND
2
2
1
e
2
2
e
O
: |
R
2
1
2
e
4: BASIC Stamp Architecture – REV, &, |
value right n number of times has the same effect as dividing that number
by 2 to the n
number 100 right three places) is equivalent to 100 / 2
Value
VAR
Idx
VAR
Value = %1111111111111111
FOR Idx = 1 TO 16
DEBUG BIN ? Value >> Idx
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).
2
2
For instance, %10101101 REV 4 would return %1011, a mirror image of the
p
sx
first four bits of the value. Example:
DEBUG BIN ? %11001011 REV 4
The And operator (&) returns the bitwise AND of two values. Each bit of
2
2
the values is subject to the following logic:
sx
p
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:
1
SYMBOL
Value1 = B0
SYMBOL
Value2 = B1
SYMBOL
Result = B2
Value1 = %00001111
Value2 = %10101101
Result = Value1 & Value2
DEBUG %Result
-- or --
2
2
DEBUG BIN ? %00001111 & %10101101
p
sx
The OR operator (|) returns the bitwise OR of two values. Each bit of the
values is subject to the following logic:
2
2
sx
p
th
power. For instance 100 >> 3 (shift the bits of the decimal
WORD
BYTE
BASIC Stamp Programming Manual 2.0c • www.parallaxinc.com • Page 73
3
. Here's an example:
' Repeat with Idx = 1 to 16.
' Shift Value right Idx places.
' Mirror 1st 4 bits (%1101)
' Show AND result (%00001101)
' Show AND result (%00001101)
Need help?
Do you have a question about the BASIC Stamp 2e and is the answer not in the manual?