Help!!!!
George Turczynski
george at hls0.hls.oz
Wed Sep 26 09:13:41 AEST 1990
In article <1990Sep21.182142.9013 at everexn.com>, roger at 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 at 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 ! ---------------------------
More information about the Comp.lang.c
mailing list