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:
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:
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:
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.
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:
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.