Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!ncar!gatech!rutgers!att!lznv!jlw From: jlw@lznv.ATT.COM (J.L.WOOD) Newsgroups: comp.unix.questions Subject: Re: Re^2: Bit Switching - How? Summary: warning Keywords: bits, flip Message-ID: <1574@lznv.ATT.COM> Date: 7 Apr 89 21:25:15 GMT References: <1138@uvm-gen.UUCP> <9977@smoke.BRL.MIL> <2345@van-bc.UUCP> <2255@solo5.cs.vu.nl> Organization: AT&T ISL Lincroft NJ USA Lines: 14 > sl@van-bc.UUCP (pri=-10 Stuart Lynne) writes: > \For fast generic swapping I use: > > \#define swap(a,b) {a^=b;b^=a;a^= b;} > Also be careful how you use this algorithm if you are using pointers. I once used this method in a sorting routine as my basic exchange and got badly burned. If a and b point to the same location, you get zero as in 0, nada, goose egg. Joe Wood jlw@lznv.ATT.COM