Bit Switching - How?
Dave Brower
daveb at gonzo.UUCP
Fri Apr 7 15:09:16 AEST 1989
In article <18944 at adm.BRL.MIL> a unidentified co-conspirator says:
>
>void bit flip(x,y,mask) int *x, *y; /* mask can be more than one bit */
>{
> int z = (x ^ y) & mask; /* difference of interesting bits */
> if (z) /* some bits differ */
> x ^= z, y^= z; /* flip those that do */
>}
I say, dear netters, that this use of the comma operator is an
abomination, and we should fear for any freshmen who come upon it as an
example of the sort of thing they ought to be writing.
Rather:
int z = (x ^ y) & mask; /* difference of interesting bits */
if (z) { /* some bits differ */
x ^= z; /* flip those that do */
y^= z;
}
If you don't see _why_ this is the right way, you'd better not work on a
project with anyone but yourself.
-dB
--
"I came here for an argument." "Oh. This is getting hit on the head"
{sun,mtxinu,amdahl,hoptoad}!rtech!gonzo!daveb daveb at gonzo.uucp
More information about the Comp.unix.questions
mailing list