Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Identify ways to use XOR logical operator
#21
i think this
Code:
flop = -flop + 1
is easier then
Code:
flipflop = flipflop XOR 1
it certainly looks shorter
[Image: sig.php]
Back by popular demand!
I will byte and nibble you bit by bit until nothing remains but crumbs.
Reply
#22
For those of us that prefer using the XOR operator, it comes as a shock when programming in another language that does not support this operator. Assuming that this language does have AND/OR/NOT operators, we can emulate an XOR as follows:
Code:
´The following performs the same as: result = a XOR b
result = (a and not(b)) or (b and not(a))
*****
Reply
#23
Quote:XOR is good, but it's a crappy name.

OR is good, AND is good. You can figure those out right off the bat.

But XOR? Come on men and women. Can't they make something cooler? Like.. "Addition of two bits without carry"

ummm... eXclusive OR? one or the other but not both?
Reply
#24
We have posted several examples of XOR for flipping the bits in a byte. Here's a reason I had to do that.

I was writing a report program whose input file was sorted on 3 keys of variable ASCII bytes. Regardless of where a sorted file comes from, I ALWAYS sequence check it while I'm reading it, otherwise the output becomes garbage and my program looks like an idiot.

The problem was that the 2nd key was sorted descending and the 1st and 3rd keys were ascending. How do you do a sequence check in this case? Normally, you concatenate the 3 keys into a combined key and just compare each combined key to the preceding for sequence, but the descending key in the middle would not work. After thinking about it for a long while, I came up with the idea of doing an XOR with 255 (hex FF) on every byte of the descending second key before placing it into the combined key. Eureka, it worked!
*****
Reply
#25
I initiated this post so I guess I should issue some final scores. There were 11 people posting (including myself), but only 6 of us actually contibuted something, in my opinion. I have assigned 1 point for concept and 1 point for a coding example. Here are the scores in posting order for the contributors:

SEPH......................... 1 point
LOOOSECABOOSE..... 2 points
DRV........................... 2 points
TOONSKI................... 1 point
ANTONI..................... 4 points (3rd example not understood)
MONEO..................... 1 point
*****
Reply
#26
In the Challenge topic re Recursion, we also saw the following use of XOR.
Code:
REM Generate Gray Code bytes; i.e. values in range from 0 to 255.
DEFINT A-Z
FOR X=0 TO 255
        GRAY = X XOR (INT(X/2))
        rem Print or output the Gray Code value in GRAY.
NEXT X
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)