TI-84 Plus CE: Bitwise Operations
Introduction
The programs NOT, AND, OR, and XOR are presented for the TI-84 Plus CE for integer in decimal base.
NOT
For integers x > 0, the NOT function is defined as:
Σ( 2^n * ( floor(x/2^n) mod 2 + 1 ) mod 2 ) from n = 0 to floor(log(x)/log(2))
However, observing the NOT operation on scientific calculators, the not function can be used for integers:
-(x + 1)
TI-84 Plus CE Program NOT
"2020-05-11 EWS"
Disp "NOT(X), X>0"
Prompt X
(X+1)→N
Disp "NOT X = ",N
Examples:
NOT 192: Returns -193
NOT -52: Returns 51
AND
For positive integers x, y and for x ≥ y, the AND function is defined as:
Σ( 2^n * ( [ floor(x/2^n) mod 2 ] * [ floor(y/2^n) mod 2 ] ) from n = 0 to floor(log(x)/log(2))
TI-84 Plus CE Program AND
"2020-05-11 EWS"
Disp "X AND Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*A*B→T
End
Disp T
Examples:
145 AND 37: Returns 1
226 AND 125: Returns 96
OR
For positive integers x, y and for x ≥ y, the OR function is defined as:
Σ( 2^n *
[ [ ( floor(x/2^n) mod 2) + ( floor(y/2^n) mod 2 ) + ( floor(x/2^n) mod 2 * floor(y/2^n) mod 2) ] mod 2 ] from n = 0 to floor(log(x)/log(2))
TI-84 Plus CE Program OR
"2020-05-11 EWS"
Disp "X OR Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*2*fPart((A+B+A*B)/2)→T
End
Disp T
Examples:
145 OR 37: Returns 181
226 OR 125: Returns 255
XOR
For positive integers x, y and for x ≥ y, the XOR function is defined as:
Σ( 2^n * [ [ floor(x/2^n) + floor(y/2^n) ] mod 2 ] from n = 0 to floor(log(x)/log(2))
TI-84 Plus CE Program XOR
"2020-05-11 EWS"
Disp "X XOR Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*2*fPart((A+B)/2)→T
End
Disp T
Examples:
145 XOR 37: Returns 180
226 XOR 125: Returns 159
Eddie
Source:
“Bitwise Operation” Wikipedia. Page last edited May 10, 2020. Accessed on May 11, 2020.
Link: https://en.wikipedia.org/wiki/Bitwise_operation
Eddie
All original content copyright, © 2011-2020. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.
Introduction
The programs NOT, AND, OR, and XOR are presented for the TI-84 Plus CE for integer in decimal base.
NOT
For integers x > 0, the NOT function is defined as:
Σ( 2^n * ( floor(x/2^n) mod 2 + 1 ) mod 2 ) from n = 0 to floor(log(x)/log(2))
However, observing the NOT operation on scientific calculators, the not function can be used for integers:
-(x + 1)
TI-84 Plus CE Program NOT
"2020-05-11 EWS"
Disp "NOT(X), X>0"
Prompt X
(X+1)→N
Disp "NOT X = ",N
Examples:
NOT 192: Returns -193
NOT -52: Returns 51
AND
For positive integers x, y and for x ≥ y, the AND function is defined as:
Σ( 2^n * ( [ floor(x/2^n) mod 2 ] * [ floor(y/2^n) mod 2 ] ) from n = 0 to floor(log(x)/log(2))
TI-84 Plus CE Program AND
"2020-05-11 EWS"
Disp "X AND Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*A*B→T
End
Disp T
Examples:
145 AND 37: Returns 1
226 AND 125: Returns 96
OR
For positive integers x, y and for x ≥ y, the OR function is defined as:
Σ( 2^n *
[ [ ( floor(x/2^n) mod 2) + ( floor(y/2^n) mod 2 ) + ( floor(x/2^n) mod 2 * floor(y/2^n) mod 2) ] mod 2 ] from n = 0 to floor(log(x)/log(2))
TI-84 Plus CE Program OR
"2020-05-11 EWS"
Disp "X OR Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*2*fPart((A+B+A*B)/2)→T
End
Disp T
Examples:
145 OR 37: Returns 181
226 OR 125: Returns 255
XOR
For positive integers x, y and for x ≥ y, the XOR function is defined as:
Σ( 2^n * [ [ floor(x/2^n) + floor(y/2^n) ] mod 2 ] from n = 0 to floor(log(x)/log(2))
TI-84 Plus CE Program XOR
"2020-05-11 EWS"
Disp "X XOR Y, X≥Y"
Prompt X,Y
0→T
For(N,0,X-fPart(X))
(X/2^N)-fPart(X/2^N)→A
2*fPart(A/2)→A
(Y/2^N)-fPart(Y/2^N)→B
2*fPart(B/2)→B
T+2^N*2*fPart((A+B)/2)→T
End
Disp T
Examples:
145 XOR 37: Returns 180
226 XOR 125: Returns 159
Eddie
Source:
“Bitwise Operation” Wikipedia. Page last edited May 10, 2020. Accessed on May 11, 2020.
Link: https://en.wikipedia.org/wiki/Bitwise_operation
Eddie
All original content copyright, © 2011-2020. Edward Shore. Unauthorized use and/or unauthorized distribution for commercial purposes without express and written permission from the author is strictly prohibited. This blog entry may be distributed for noncommercial purposes, provided that full credit is given to the author.