Post comments on this article and find any associated files and/or downloads at
500 m=1 SHL 31 REM <——Look at MSB First
505 FOR i=0 TO 31
510 r=m & n REM <——Apply Single Bit Mask
515 IF r THEN PRINT “1”;: GOTO 525
520 PRINT “0”;
525 m=m SHR 1 REM <——Slide Mask One Bit Right
530 NEXT i
Operation Action Performed
a SHL b
Shift Left. Shifts each bit in a, b times to the
left. Bit 31 (the most significant bit) is
discarded each shift, and bit 0 is set to zero.
a SHR b
Shift Right. Shifts each bit in a, b times to the
right. Bit 0 (the least significant bit) is
discarded each shift, and bit 31 is set to zero.
a ROL b
Rotate Left. Shifts each bit in a, b times to the
left. Bit 31 (the most significant bit) is moved
to bit 0 (the least significant bit) each time.
FIGURE 2: Using BINARY.BAS to explore Color BASIC
a ROR b Rotate Right. Shifts each bit in a, b times to the right. Bit 0 is moved to bit 31 each time.
• Then, Line 525 uses SHR to slide the 1 in bit 31 of the
mask one bit to the right, and the FOR/NEXT loop repeats
the process for the remaining 31 bits of n.
Figure 2 shows BINARY.BAS in action; it should be
easy to see the results of various bitwise operations.
Here’s a tip not mentioned in my original overview of
Color BASIC that may be helpful. Color BASIC implements
both the prefix for binary numbers and the prefix for
hexadecimal ones. So, you can enter a specific bit pattern
into a variable with v = %1011001110001111, for
instance, or print the decimal value of a hex number with
PRINT $FFCEB. Try including binary or hex values in the
input expression of BINARY.BAS and watch what happens.
a SAR b
Arithmetic Shift Right. Shifts each bit in a, b
times to the right. Preserves the sign bit (bit
31 keeps its original value); bit 0 is discarded
a REV b
Bit Reverse. Reverses the order of b least
significant bits in a and sets the remaining
bits to zero.
a & b
Bitwise logical “and.” Compares the values in
a and b bit-by-corresponding-bit and places a
1 in that bit of the result if the bits from a and
b are both 1. Places a 0 in that bit otherwise.
Bitwise logical “or.” Compares the values in a
and b bit-by-corresponding-bit and places a 1
in that bit of the result if either bit from a and
b (or both) is 1. Places a 0 in that bit
a | b
FIGURE 1: The Color BASIC 2.2L bitwise operators —
more tools for your Amigo toolbox!
A quick look at this code snippet should reveal no
surprises until the subroutine in Lines 495-535, where we
see a couple of bitwise operators at work:
• Line 500 uses SHL to initialize bit mask m, placing a
one in bit 31 and zeroes in bits 0 through 30 by left-shifting “1” 31 times.
• Then, Line 510 conducts a bitwise logical & of this
mask and n (the 32-bit signed integer) which results from
evaluation of the expression that was input in Line 20.
Let’s look at the SRAM commands now. You may
recall that the Amigo sports 32K of SRAM, but my
introductory Color BASIC commands set offered no
commands to access that storage. (This was an oversight
on my part, and one for which I sincerely apologize.) As
shown in Figure 3, there are only three SRAM commands
in Color BASIC, and they are easy to understand and use.
As you can see, Color BASIC uses the typical PEEK
<address> instruction to read from memory and POKE
<address>, <value> to write. For the Amigo SRAM, values
read or written are eight-bit bytes, and they will remain in
SRAM until power is removed, or a CLEAR or REBOOT
command is issued. This means you can use SRAM to
• If bit 31 of n is one, the result of m & n will be
nonzero; the IF statement in Line 515 is TRUE and prints
1. Otherwise, bit 31 is zero, and Line 520 prints 0.
Dane Weston’s book on Color BASIC for the
Pocket Mini Computer is available at
Application Note on Propeller Cog Counters is available at
50 July/August 2018