Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/12/84; site desint.UUCP Path: utzoo!watmath!clyde!bonnie!akgua!sdcsvax!sdcrdcf!trwrb!desint!geoff From: geoff@desint.UUCP (Geoff Kuenning) Newsgroups: net.lang.c Subject: Re: reversing a mask Message-ID: <242@desint.UUCP> Date: Sun, 25-Nov-84 18:14:41 EST Article-I.D.: desint.242 Posted: Sun Nov 25 18:14:41 1984 Date-Received: Wed, 28-Nov-84 01:41:07 EST References: <1@imd.UUCP> <469@ncoast.UUCP> <691@gloria.UUCP> Organization: his home computer, Manhattan Beach, CA Lines: 24 In article <691@gloria.UUCP> colonel@gloria.UUCP (George Sicherman) writes: >What's the fastest way to reverse a 16-bit mask in C? In 68000 asl? >(Maybe this should be in net.puzzle!) Try this: static unsigned char revtab[256] = {0x80, 0x40, 0xC0, 0x20, 0xA0,...}; short bitrev (mask) register unsigned short mask; { return (revtab[mask & 0xFF] << 8) | revtab[mask >> 8]; } Note: I haven't actually tried compiling this program. It depends on the compiler generating a zero-filling right-shift for unsigned shorts. If yours does not, you will need to use: return (revtab[mask & 0xFF] << 8) | revtab[(mask >> 8) & 0xFF]; -- Geoff Kuenning ...!ihnp4!trwrb!desint!geoff