The fastest way I found to do bitwise operations on integers is this:

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

where E=2^-13 and L₂=2^(13-cumsum(binomcdf(31,0)))

It's just as fast as a lookup table from a matrix.

]]>The code I'm using to convert a number into a list of bits is modified from the linked page:

` ``int(2fPart(Ans⁻¹(N`

However, this code breaks for large numbers (thus wasting a lot of my time) because of the negative exponent. Infuriatingly, fPart(2^-31 * 2^31) = 1 and int(2^-31 * 2^31) = 0, even though 2^-31 * 2^31 = 1, due to some odd rounding error. A better solution is to use division instead:

` ``int(2fPart(N/Ans`

In case anyone else wants to use this method, the code to convert from a list of bits back into a number is pretty simple, also modified from the linked page:

` ``sum(.5AnsL1`

In all of these cases Ans actually refers to 2^cumSum(binomcdf(31, 0)).

]]>Well hope to see you more, I don't even know what a bitwise is, hope you finished that chemistry formula equating thing

]]>Again, thanks for your help!

]]>` ``AsmPrgmEFD74A3DC0EB2323E7E5EFEF4AE1F5E7EFEF4AC1 A0 26006FEF9247EF5641EFBF4AC9`

The line with "A0" can be changed to A8 for XOR, or B0 for OR. The assembly code is:

` ``#include "ti83plus.inc" #define progStart $9D95 .org progStart-2 .db $BB,$6D bcall(_RclAns) dec a ret nz ex de,hl inc hl inc hl rst 20h push hl bcall(_ConvOP1) pop hl push af rst 20h bcall(_ConvOP1) pop bc and b ;change this to "xor b" or "or b" as needed ld h,0 ld l,a bcall(_SetXXXXOP2) bcall(_OP2ToOP1) bcall(_StoAns) ret`

I just put that in ClrHome's ORG to compile as a TI program file (8XP). ]]>

This post is rather similar to /forum/t-137688 (sorry, I can't link) from five (!) years ago.

I'm trying to find a way to perform the AND, OR, and XOR bitwise operations on 32-bit numbers very quickly. I've already written a method that does then in around 1.3 seconds, and further reduced that to 0.7 seconds by using a 16x16 matrix (transferred from the computer) to store the result for all AND/OR/XOR possibilities of 4 bits. (Getting desperate…)

So I was wondering if there's any way to do this faster? Maybe there is an assembly program that could help do this? Bitwise operations should be fairly fast for the processor, in fact, faster than adding, which makes this problem amusing.

(In case anyone is wondering, I'm trying to implement the SHA-1 hash algorithm. It uses a LOT of bitwise operators: my current program takes minutes to run vs milliseconds on a computer. I've seen calccrypto's work and it's pretty awesome!)

Thanks everyone!

]]>