Bitwise functions for 27S?
06-05-2017, 07:37 PM
Post: #2
 Dave Britten Senior Member Posts: 2,251 Joined: Dec 2013
RE: Bitwise functions for 27S?
Alright, here's my attempt at it, then. Not the fastest thing in the world, but it gets the job done in a pinch. Note that it expects (and returns) decimal values. If you want to use non-decimal numbers, enter/convert them in the BASE menu and store into scratch registers for recalling in the solver.

Enter your operands into A and B, and solve for the operation you want. #NOT works a little differently - it inverts the bits in A, and uses the value in B as the word size, i.e. the result will be padded/trimmed to B bits, as appropriate. This isn't designed to handle any goofy inputs (non-integers or negative values). And if you give it a huge value for B when calculating #NOT, be prepared to wait.

Code:
BITS: 0*(L(A1:A)+L(B1:B)+L(D:IP(LOG(IF(A>B:A:B))÷LOG(2)))) +Σ(X:0:IF(S(#NOT):B-1:G(D)):1:   0*L(C3:(L(C1:MOD(G(A1):2))+MOD(G(B1):2)))   +IF(S(#AND):IF(G(C3)=2:1:0):     IF(S(#OR):IF(G(C3)>0:1:0):       IF(S(#XOR):IF(G(C3)=1:1:0):         IF(S(#NOT):IF(G(C1)=0:1:0):0)       )     )   )*2^X   +0*(L(A1:IDIV(G(A1):2))+L(B1:IDIV(G(B1):2))) ) =IF(S(#AND):#AND:   IF(S(#OR):#OR:     IF(S(#XOR):#XOR:       IF(S(#NOT):#NOT:0)     )   ) )

I think this would work on the 17BII, 19BII, and palmtops (I developed it on my 200LX). If any of those models doesn't have the IDIV function, just substitute IP(X÷Y) as appropriate.