[3.24] Use Equations To Build Lists Of Lists And Matrices - Texas Instruments TI-89 Tip List

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

Advertisement

Func
©(wordOrList,bit#) test bit#
©22may01/dburkett@infinet.com
local k,msg,type
"bittst() err"→msg
gettype(x)→type
when(type="NUM",when(b<0 or b>31,msg,exact((x and 2^b)≠0)),
when(type="LIST",when(b<0 or b>32*dim(x)-1,msg,exact((x[k] and
2^(b-(k-1)*32))≠0)|k=1+intdiv(b,32)),msg))
EndFunc
All of the calculation for each function is performed with a single nested when() function: even though
the listings above show three lines, each when() is a single TIBasic line. If the argument is a single
integer, the function tests the bit number argument to ensure that it is between 0 and 31, since an
integer has 31 bits. If the flags argument is a list, the functions test to ensure that the bit number
argument is greater than zero, and less than or equal to the total number of bits less one, which is
found by the expression 32*dim(x)-1.
For each function, a bit mask of the form 2
zeros except for a 1 in the bit number argument position. For example, if the bit number is 4, then the
bit mask is 0b10000. If the flags argument is a list, the bit mask is in the form 2
the correct bit (from 0 to 31) in list element k. The list element k is found from the expression
1+intdiv(b,32), where b is the bit number input argument. In either case, the desired bit is set, cleared
or inverted with a simple boolean expression:
where x is the flags integer. From the boolean function truth tables shown above, you can verify that
these operations result in the desired effect for the different functions. Note that each boolean
operation is executed as the argument to exact(), which ensure proper results if the mode is set to Auto
or Approx when the function is called.
If the flags argument is a list, then bitset(), bitclr() and bitnot() use a nested augment() function to
assemble the original list elements, along with the changed element, into the returned list.
bittst() works a little differently, since it must return a true or false result. bittst() uses the boolean
expression
exact((x and 2^b)≠0)
where x is the flags integer, and 2
number b is set, otherwise it returns false.

[3.24] Use equations to build lists of lists and matrices

It is usually not possible to create a list consisting of other lists. This returns an Invalid list or matrix
error:
{3,{1,2},{3,4}}
b
b
bitset() uses x or 2
b
bitclr() uses x and 2
b
bitnot() uses x xor 2
b
is the bit mask described above. This expression returns true if bit
is used to perform the required function. The bit mask is all
b-(k-1)*32
, which chooses
3 - 27

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Ti-92+

Table of Contents