Full Version: Sorting 2 variables: one ascending, one descending
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2 3
NEO: The XOR solution is exactly what I was hinting at. Another gold star for you, Neo. Here's a piece of code from an old program of mine which does exactly this.
complement:             'Complement each key byte for DESCENDING
  for zz = 1 to len(k$)
      mid$(k$,zz,1) = chr$( asc(mid$(k$,zz,1)) XOR 255 )
  next zz
RETURN     '>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
An XOR of any byte with 255 will produce the complement of the original byte value. This is known as the one's complement, which means that every 1 becomes a 0, and every 0 becomes a 1.

MEG: Thanks for letting TOOH have it with both barrels. Yes I'm posting from Mexico City. Timezone-wise that's the same time as Chicago. I don't post at strange times, usually at night when I get home from work.

About the sayings. The Turkish one I got from my first mother-in-law who was a Greek born in Istanbul. She quoted this saying all the time as being Turkish. Let's keep in mind that this lady was born in 1900, so the saying could be outdated.
The one about singing out of the same hymm book comes from an American saying that a person who is not 100% mentally, is "not singing out of the same hymm book". This saying too may be outdated since I'm 66 years old and can't remember how long ago I heard it. It is real, however.

I love old sayings. A programmer friend of mine called Mick, who was born in Texas, used to quote sayings from his mother all the time. My favorite was: "Im so tired, I feel like I've been ironing all day with a cold iron¨. You've got to hear it with a Texas drawl.
Quote:I suppose if the sorting column were alphanumeric, you would be better off "subtracting" it from a string of CHR$(255)'s. For each character "x" in the string, replace it with CHR$(255-ASC("x")) in the sortkey.
MEG: Forgive me. In my last post I was so excited with the fact the Neo came up with the XOR solution, that I neglected to acknowledge your equally elegant solution with has exactly the same effect using arithmetic instead of the XOR bit-wise logic.

I consider that both you and Neo are the co-winners of the challenge by demonstrating that manipulation of the sort key can solve an otherwise sticky sorting problem. Hurrah to you both. Big Grin
Thanks very much Moneo Big Grin I almost feel special...

but there's one lady who's more special: Meg! Congratulations on co-winning and a [Image: new_birthday.gif] Hurray!
You have a great algorithmic thinking mind... Wink

Btw, 255 - A is exactly the same as A XOR 255.
I can see that what I was asking was not a simple thing. Yikes. I'll have to wait awhile before my mind can grasp all that. But I found that program wasn't really useful to me so I'll forget about it for now and challenge myself another day.
Neo, Don't even think about it --- you are special. Big Grin
Quote:Neo, Don't even think about it --- you are special. Big Grin
Nah... thanks Moneo Wink
Ok ok, I'm special Wink But I still don't refrain from my previous statement, so: I may be special, then Meg is more special Wink

*I'm collecting gold stars* Wink
Pages: 1 2 3