Does anyone have some code that performs a bitwise XOR operation on two numbers?

Thanks in advance Smile
If you were able to put the bin in a string with DCS7 commands, you could do something like:

:" "→str3
:If B xor C

I fixed it! It furs out I was using the wrong variable in the code that called this program, here's the source in case anyone would like to see it:

While F<S or F<E
If A<=E and A>=S and (D xor L):R+(2^(A-1))->R

N = 1st number
Z = 2nd number
R = Output
S = Starting bit to calculate from
E = Ending bit to calculate to
I came up with the following technique, but I know Weregoose is about to ninja this post with the code he posted on IRC after you logged off last night. My version performs A xor B -> C. Shameless fact: I ripped off the complex number concept from Weregoose.


I am sure I can shrink the code that figures out how many bits to compute. Anyway, here's how that works:

1) Computes the number of binary digits that will need to be generated: ~min(int(~log(A)/log(2)),int(~log(B)/log(2. This uses a pair of change of base operations plus a quirk of the int() command to get the ceiling of the two numbers of digits, and effectively gets the max of the two.
2) Computes a complex number for each bit indicating the value of the bit in A and B: fPart((A+Bi)/(2^X)).
3) Make sure that it's either 1+0i or 0+1i: 1=abs(int(2...))
4) Give each resulting bit its proper place value: .5(2^X)
5) Generate a list of place-valued bits and sum them: sum(seq(
Wow, thanks! I'll post my other bitwise operation code (AND, Shift, OR), I'm sure you'll come up with a one liner for those Very Happy
Let's see how similar these end up being...


If you want to retool this into another bitwise operation, go to the "=" and substitute it with "<" for AND, or "≤" for OR.


Three fewer bytes and noticeably faster:

Wow, that is fantastic!
I have one question though, what is the ⁻¹ symbol?
the emulator won't accept it.

EDIT: Found it on catalog
SamTebbs33 wrote:
Wow, that is fantastic!
I have one question though, what is the ⁻¹ symbol?
the emulator won't accept it.

EDIT: Found it on catalog

It comes from the x⁻¹ key, right below MATH and above the x-squared key.
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum