On Mon, 3 Nov 1997, George wrote:
->On Mon, 3 Nov 1997, Daniel Koepke wrote:
->
->> a = a xor b;
->> b = b xor a;
->> a = a xor b;
->>
->>I just use the macro "#define SWAP(a,b) { a ^= b; b ^= a; a ^= b }".
->>Even if a lot of people knew this one, I doubt it has any use in
->>CircleMUD.
->
->It's used in class.c, line 239.
Oh, wow, you're right...Okay, it is used in CircleMUD. BTW, it also
seems possible with addition and subtraction, although I didn't think
of this until someone else mentioned that it could be done (in
disbelief, I spent 2 minutes figuring out how/if):
When a = 1 and b = 2:
a = 1 + 2; a = 3;
b = 3 - 2; b = 1;
a = 3 - 1; a = 2;
When a = 5 and b = 9:
a = 5 + 9; a = 14;
b = 14- 9; b = 5;
a = 14- 5; a = 9;
When a = 10 and b = 20:
a = 10+20; a = 30;
b = 30-20; b = 10;
a = 30-10; a = 20;
Imagine that...BTW, last I checked, the xor method was portable. I
don't know what the other person was talking about, though. So if
there is yet another way, please inform.
daniel koepke / dkoepke@california.com
+------------------------------------------------------------+
| Ensure that you have read the CircleMUD Mailing List FAQ: |
| http://democracy.queensu.ca/~fletcher/Circle/list-faq.html |
+------------------------------------------------------------+
This archive was generated by hypermail 2b30 : 12/08/00 PST