BASIC stamp manual v2.2
BASIC Stamp Architecture – >>, REV, &, |
Page 118 • BASIC Stamp Syntax and Reference Manual 2.2 • www.parallax.com
lost; bits shifted into the left end of the number are 0s. Shifting the bits of a
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 BIN16 ? 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 right-most bit (least
significant bit or “lsb”). For instance, %10101101 REV 4 would return
%1011, a mirror image of the right-most four bits of the value. Example:
DEBUG BIN4 ? %10101101 REV 4 ' Mirror 1st 4 bits (%1011)
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 = B2
SYMBOL value2 = B3
SYMBOL result = B4
value1 = %00001111
value2 = %10101101
result = value1 & value2
DEBUG %result ' Show result of AND (%00001101)
-- or --
DEBUG BIN8 ? %00001111 & %10101101 ' Show result of AND (%00001101)
The OR operator (|) returns the bitwise OR of two values. Each bit of the
values is subject to the following logic:
REVERSE: REV
All
2
1
A
ll
2
1
A
ll
2
1
All
2
AND: &
O
R: |