reversing a mask
Geoff Kuenning
geoff at desint.UUCP
Mon Nov 26 09:14:41 AEST 1984
In article <691 at gloria.UUCP> colonel at 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
More information about the Comp.lang.c
mailing list