WDS> Let w be a 64-bit word ("unsigned long long," in C language). The following C instruction sequence w ^= w>>32; w ^= w<<32; w ^= w>>32; w ^= w>>16; w ^= w<<16; w ^= w>>16; w ^= w>>8; w ^= w<<8; w ^= w>>8; w ^= w>>4; w ^= w<<4; w ^= w>>4; w ^= w>>2; w ^= w<<2; w ^= w>>2; w ^= w>>1; w ^= w<<1; w ^= w>>1; will overwrite w with its bit-order-reversal. In general for a (2^k)-bit long word this will use 3*k shifts and 3*k XOR operations and with zero(?) or one(?) extra registers consumed for temp storage and no funny masking constants needed. -- Warren D. Smithhttp://RangeVoting.org Knuth Vol 4A, 7.1.3 has 70 pages on Bitwise Tricks and Techniques. Page 144 is Bit reversal, and may anticipate you here--I haven't read closely enough to determine. (Probably not, if Tom Karzes's "all 1s" objection resists debugging!) Certainly most of Knuth's hacks require "funny masking constants" (whose objectionability I fail to perceive). Probably the most important lesson in 7.1.3 is Knuth's strong advocacy of his MOR and MXOR (8×8 bitmatrix) instructions for inclusion in 64-bit order codes. Bit reversal takes two MORs. --rwg After Bit reversal comes Bit swapping, in which my hasty perusal fails to find the TRCE TRCE TRCE trick (HAKMEM Item 162), of which Knuth was once quite fond. It is perhaps too platform dependent? I'd think he would cite TRCE etc as ideas for future order codes, but perhaps instruction skipping is a thing of the past.