Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!samsung!munnari.oz.au!metro!wolfen!hls0!george From: george@hls0.hls.oz (George Turczynski) Newsgroups: comp.lang.c Subject: Re: Help!!!! Message-ID: <937@hls0.hls.oz> Date: 25 Sep 90 23:13:41 GMT References: <26f8528c.35c1@uop.uop.edu> <1990Sep21.182142.9013@everexn.com> Lines: 29 In article <1990Sep21.182142.9013@everexn.com>, roger@everexn.com (Roger House) writes: [...Deleted...] > > Say B is the variable for which bits 2 and 5 are to be swapped. Then this > code will do the trick, although it requires the use of another variable, > t: > > if ((t = B & 0x24) && t != 0x24) /* Swap bits 2 and 5 of B */ > B ^= 0x24; > > There are probably better ways to do it. > Well, to do a similar thing without the use of a temporary, try this: B= !!(B&0x20)^!!(B&0x4) ? B^0x24 : B; This follows from your truth table (that I deleted), as the result is only different if bits 5 and 2 are different (which is what the curious looking test, !!(B&0x20)^!!(B&0x4), finds out). -- George P. J. Turczynski, Computer Systems Engineer. Highland Logic Pty Ltd. ACSnet: george@highland.oz |^^^^^^^^^^^^^^^^^^^^^^^^| Suite 1, 348-354 Argyle St Phone: +61 48 683490 | Witty remarks are as | Moss Vale, NSW. 2577 Fax: +61 48 683474 | hard to come by as is | Australia. --------------------------- space to put them ! ---------------------------