Texas Instruments TI-89 Tip List page 106

Graphing calculator
Hide thumbs Also See for TI-89:
Table of Contents

Advertisement

We can simultaneously test several status flags by using a mask. A mask is simply an integer with
certain bits set or cleared, as needed to perform some desired operation. We will use the built-in
boolean operators and, or, xor and not to perform mask operations. For example, suppose we want to
execute a block of code if flags 0, 4 and 7 are all set. The mask to test these flags would be
0b10010001, and the code would look like this:
if status and 0b10010001=0b10010001 then
... {block} ...
endif
The result of and-ing the mask with status will only equal the mask if the mask bits are set. This
method also provide more flexibility than the corresponding test with separate boolean variables,
because the mask can be a variable, which can be changed depending on program requirements.
We can also use masks to perform other manipulations and tests. First, these truth tables show the
operation of the built-in boolean operators.
a
b
a and b
0
0
0
1
1
0
1
1
You can use these truth tables to determine the mask values and boolean operators needed to perform
different tests and manipulations, as shown:
Description
Set a group of flags
Clear a group of flags
Invert a group of flags
Invert all the flags
Return true if all of a
group of flags are set
Return true if any of a
group of flags are set
Masks can be used with lists of integers, as well as with individual integers. For example, suppose that
flags = {0b0110,0b1100} and mask = {0b1111,0b1000}, then
a
0
0
0
0
0
1
1
1
Mask bit description
0: the corresponding
flag bit is unchanged.
1: The corresponding
flag bit is set.
0: the corresponding
flag bit is cleared.
1: the corresponding
flag bit is unchanged
0: the corresponding
flag bit is unchanged.
1: the corresponding
flag bit is inverted
(none)
0: ignore the flag bit in
the test.
1: include the flag bit in
the test
0: ignore the flag bit in
the test.
1: include the flag bit in
the test
b
a or b
0
0
1
1
0
1
1
1
Operation
flags or mask
flags and mask
flags xor mask
not flags
flags and mask = mask
flags and mask ≠ 0
a
b
a xor b
0
0
0
0
1
1
1
0
1
1
1
0
Example
Set flags 2 and 3:
flags = 0b0001
mask = 0b1100
result = 0b1101
Clear flags 0 and 3:
flags = 0b0111
mask = 0b1001
result = 0b0001
Invert flags 1 and 2:
flags = 0b0011
mask = 0b0110
result = 0b0101
flags = 0b1010
result = 0b0101
flags = 0b0111
mask = 0b0110
flags and mask =
0b0110
result = true
flags = 0b0101
mask = 0b0110
flags and mask =
0b0100
result = true
3 - 24

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents