Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.1 6/24/83; site mit-eddie.UUCP Path: utzoo!watmath!clyde!burl!ulysses!allegra!mit-eddie!smh From: smh@mit-eddie.UUCP (Steven M. Haflich) Newsgroups: net.lang.c Subject: Re: reversing a mask Message-ID: <3178@mit-eddie.UUCP> Date: Sun, 25-Nov-84 08:42:43 EST Article-I.D.: mit-eddi.3178 Posted: Sun Nov 25 08:42:43 1984 Date-Received: Mon, 26-Nov-84 02:04:37 EST References: <1@imd.UUCP> <469@ncoast.UUCP> <691@gloria.UUCP> <4082@elsie.UUCP> Reply-To: smh@mit-eddie.UUCP (Steven M. Haflich) Organization: MIT, Cambridge, MA Lines: 14 Much more space-efficient and only slightly slower is the following: char revbytes[256] = { 0x00, 0x80, 0x40, 0xc0, ... , 0x7f, 0xff }; #define reverse(v) ((revbytes((v)&0xff)<<8)|revbytes(((v)>>8)&0xff)) That's the general idea. This is not perfectly portable, but then, neither was the original problem. Depending on particular C implementation, various dodges may be necessary to prevent the infamous char sign extension problem: either by declaring revbytes to be "unsigned char", or else by anding each mention of revbytes with 0xff. Also, note that the argument gets evaluated twice, but this could be corrected if necessary. Steve Haflich