Re: swap two integers without using a tmp variable?
From: Steve (ngsteve_at_my-deja.com)
Date: 06/22/04
- Next message: Branimir Maksimovic: "Re: Ultimate Efficiency"
- Previous message: Ioannis Vranos: "Re: Ultimate Efficiency"
- In reply to: Walter Tross: "Re: swap two integers without using a tmp variable?"
- Next in thread: Richard Herring: "Re: swap two integers without using a tmp variable?"
- Reply: Richard Herring: "Re: swap two integers without using a tmp variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: 22 Jun 2004 05:44:36 -0700
The xor solution was really elegant. I would not have thought about it
and never knew it could be done this way.
X XOR Y XOR Y = X (assign in y variable, cancel out both Y)
X XOR Y XOR X = Y (assign in x variable, cancel out both X)
Thanks for the help.
- Next message: Branimir Maksimovic: "Re: Ultimate Efficiency"
- Previous message: Ioannis Vranos: "Re: Ultimate Efficiency"
- In reply to: Walter Tross: "Re: swap two integers without using a tmp variable?"
- Next in thread: Richard Herring: "Re: swap two integers without using a tmp variable?"
- Reply: Richard Herring: "Re: swap two integers without using a tmp variable?"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|