TI-84 BASIC doesn't have bitwise operators. This is too bad, because in certain applications they would really improve speed. You may think after reading this, "why doesn't lirtosiast just learn Axe or C or something instead", to which I respond what's the fun of that?

Anyway, it seems impossible to have bitwise and/or/xor any faster than the logical and/or/xor on lists, which takes about 1? ms (or 15000 cycles) per list element. Converting lists of bits to reals is even slower; this is close to the fastest way to convert two numbers to 32-bit lists, logical AND, and then convert back:

Quote:
Where E=2^-13 and L₂=2^(13-cumsum(binomcdf(31,0))), this is as fast as the matrix method:

Code:
//and (0.242 seconds)
sum(L₁round(min(fPart(AEL₂),fPart(BEL₂)),0))


16 bits still takes, I imagine, upwards of 0.1 seconds.

I thought for a while about any way to implement bitwise operators or anything like them that could do multiple things in parallel for one operation on a real, like prime products, but those are limited. Now I think I have a solution based on unadjusted floats—that is, floats that contain hex A-F, which aren't supposed to be in BCD numbers. When these are added internally using addition followed by the daa instruction, there are some errors when digits are greater than 9. In particular, when the sum of two digits is greater than 26h, the answer is wrong:


Code:

//result should be 15+12=27
   0  F
+  0  C
-------
   1* B   //"*" represents H flag
[daa adds 06h]
   2* 1


This is because two carries should be done, but the daa instruction is actually done only once. I tested the 84+'s actual addition algorithm, and it does the same thing. This suggests doing something like the following in TI-BASIC:


Code:
A+V+V-W-W


Where A is the number to detect digits greater than 5 in, V is 0x0080FFFFFF..., and W is its adjusted counterpart. V will need to be edited using an assembly program, but the rest is pure BASIC. Whenever A has a digit greater than 5, the sum will be less than it should be. This can probably somehow lead to a bitwise AND-like operation.

I haven't figured out how to prevent some digits from corrupting others, though—will update when I actually figure out how to do anything useful with this.
It's more complicated than I thought; here are some addition results (mostly for me to look over):

Code:

2.005 + 1.00F = 3.01A  //as expected
3.01A + 1.00F = 4.02F
4.02F - 1.000 = 3.029  //6 less than should be, because daa subtracts 06h from the nibble F
4.02F - 1.005 = 3.024
4.02F - 1.006 = 3.029
3.029 - 2.005 = 1.024  //as expected


EDIT: I found out two things:

* Subtraction is easier than addition because it can be done in one step. When a digit is greater than 9, 6 is subtracted. So if we subtract from F, the sum will be missing 6 in that place if the subtrahend is 5 or less.

* The amount missing from the sum actually varies depending on the place value. If in a high nibble, the result of daa setting the c flag is that the next digit up is decremented. So 16 is missing, not 6. Therefore, it's probably only feasible to compute one thing for every two digits. Also, the first digit and last digit probably can't be used, so there can only be 5 operations done. This limits the utility.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement