Visit Atarimax Store


Free-Net Logo
The Atari SIG Historical Archive
Created and hosted by: atarimax.com
[ HOME | GO ATARI | 8-BIT | ST/TT | PORTFOLIO | LYNX | JAGUAR | LIBRARY ]


Article #114 (145 is last):
Newsgroups: freenet.sci.comp.atari.library
From: aa700@cleveland.Freenet.Edu (Michael Current)
Subject: Understanding Binary Operations
Posted-By: xx004 (aa700 - Michael Current)
Reply-To: aa700@cleveland.Freenet.Edu (Michael Current)
Date: Tue Jan 28 22:33:39 1992


Reprinted from the A.C.E.C. BBS (614)-471-8559

-----------------------------------
  Understanding Binary Operations
-----------------------------------

The 6502 Processor, the CPU which
all Atari, Apple, and Commodore
8-bit computers use, supports three
bit manipulation functions.  These
functions can be very powerful in
various circumstances--in both
BASIC and especially Machine
Language.  Though Atari BASIC does
not truly support these functions,
BASIC XE and other similar
extentions of BASIC do offer them
to the BASIC user.  It is assumed
throughout this article that the
user is familiar with binary and
decimal, as well as conversions
between them.

One term must be defined before we
go further.  A "mask" is a number
that is used with any of these
operations.  You must have a mask
to use them.

First we will cover the AND
function.  This function is very
much self explanatory.  If the bit
in the original number AND in the
mask are 1, then the result will be
1.  If the bit in either of the
numbers is 0, then the resulting
bit will be 0.  To demonstrate this
(and all of these functions), we
will look at it in both binary and
decimal notation.
 Bit "Identifier":      ABCDEFGH
 -------------------------------
 Original Number:  51 = 00110011
 Mask Number:      15 = 00001111
 Resulting Value:   3 = 00000011

This says "The value 51 ANDed with
15 is 3".  As you can see, bits G
and H contain 1's in BOTH the
original number and the mask.
Because of this, bis G and H are
set in the resulting value.  Bits
E and F are not set because the
original number contains 0's in
these bits.  Bits C and D are not
set because the mask number
contains 0's in these bits.  THE
AND FUNCTION IS GENERALLY USED TO
ZERO OUT UNWANTED BITS.  For
example, if you are getting input
but are not interested in whether
or not it is inverse (that is, has
an ATASCII value of 128 or more),
then you could AND the input with
127.  This will cause all input to
be normal, un-inverse characters.
In Machine Language, the format is:
AND #mask.  The Acumulator will
then be ANDed with the mask and the
result will be stored in the
accumulator.

Next we will deal with the OR
function.  With this function, if
a bit is set in EITHER OR BOTH the
original or the mask, then the
resulting bit will be set.  Here is
our demo of
this function:
Bit "Identifier"       ABCDEFGH


Visit Atarimax Store