Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Challenge: Identify ways to use XOR logical operator
#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


Messages In This Thread
To Seph: - by Moneo - 06-21-2003, 07:41 AM
To LooseCaboose: - by Moneo - 06-21-2003, 08:59 AM
To drV: - by Moneo - 06-21-2003, 09:24 AM
Re: To drV: - by DrV - 06-21-2003, 09:39 AM
To Toonski84 - by Moneo - 06-21-2003, 10:03 AM
Re: To drV: - by relsoft - 06-22-2003, 02:20 PM
Sample reason for using XOR. - by Moneo - 06-23-2003, 09:33 PM
Update: - by Moneo - 07-03-2003, 11:32 PM

Forum Jump:


Users browsing this thread: 1 Guest(s)