Post Reply 
(27S) Bitwise operators (AND, OR, XOR, NOT)
06-12-2017, 12:12 AM
Post: #1
(27S) Bitwise operators (AND, OR, XOR, NOT)
Line feeds and indentation added for clarity. This should also work on a 17B, 17BII, 19B, 19BII, 95LX, 100LX, or 200LX.

Code:

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)
    )
  )
)

Variables:

A - First operand
B - Second operand (or word size for NOT)
#AND - Result of "A AND B"
#OR - Result of "A OR B"
#XOR - Result of "A XOR B"
#NOT - Result of "NOT A" with word size B bits

Usage:

Enter the two operands into A and B, then solve for #AND, #OR, #XOR, or #NOT to compute the result. For the binary functions (AND, OR, XOR), A and B are the two operands. For the unary NOT, A is the operand, and B is the word size in bits. NOT assumes unsigned input and output.

All values are entered and returned as decimal integers. Use the BASE menu and store converted values to teporary registers for working with non-decimal values.

Examples:

Compute 66532 AND 21556.

66532 {A}
21556 {B}
{#AND} 36

Compute 384 OR 28.

384 {A}
28 {B}
{#OR} 412

Compute 923 XOR 7777.
923 {A}
7777 {B}
{#XOR} 7674

Compute NOT 4872 with word size of 16 bits.
4872 {A}
16 {B}
{#NOT} 60663
Visit this user's website Find all posts by this user
Quote this message in a reply
Post Reply 




User(s) browsing this thread: 2 Guest(s)