Relay-Version: version B 2.10 5/3/83; site utzoo.UUCP Posting-Version: version B 2.10.2 9/5/84; site cadomin.UUCP Path: utzoo!watmath!clyde!cbosgd!ihnp4!alberta!cadomin!jim From: jim@cadomin.UUCP (Jim Easton) Newsgroups: net.puzzle Subject: Another code puzzle Message-ID: <360@cadomin.UUCP> Date: Fri, 22-Mar-85 18:54:04 EST Article-I.D.: cadomin.360 Posted: Fri Mar 22 18:54:04 1985 Date-Received: Sun, 24-Mar-85 04:29:18 EST Distribution: net Organization: U. of Alberta, Edmonton, AB Lines: 26 For the line eater. Since we're doing code puzzles try this one. I make no claims for efficiency - It's a C version of some code I wrote for a Honywell on which it took only three instructions and ran like stink. Jim@alberta /* comments have been deliberately omitted */ #define NBITS 9 /**/ int doit(arg) short arg; { long unsigned register pick, flip, work; int register i; pick = 1 << NBITS; flip = pick - 1; work = (arg & flip) << NBITS; for (i = 0; i < NBITS; i++) { if (work & pick) work ^= flip; work = work >> 1; } return ((int) work); }