Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: More bit reversal...

Author: Matt Taylor

Date: 17:26:25 01/24/03

Go up one level in this thread


On January 24, 2003 at 14:49:27, Dann Corbit wrote:

>Convolution:
>http://beige.ucs.indiana.edu/B673/node14.html
>
>From :
>http://claymore.engineer.gvsu.edu/~blaucha/C2D2/The%20C%20Cheat%20Sheet.pdf
>
>int             reverse(int i)
>{                               // Assumes int is a 32-bit integer
>    int             mask;
>    int             rev;
>    int             orvalue;
>    for (rev = 0, mask = 0x80000000, orvalue = 1;
>         mask != 0;
>         mask = mask >> 1, orvalue = orvalue << 1) {
>        rev = rev | ((i & mask) ? orvalue : 0);
>    }
>    return rev;
>}
>
> Which I would rewrite as:
>
>
>int             reverse(int i)
>{                               // Assumes int is a 32-bit integer
>    int             mask;
>    int             rev;
>    int             orvalue;
>    for (rev = 0, mask = 0x80000000, orvalue = 1; mask != 0; mask >>= 1, orvalue
><<= 1) {
>        rev |= ((i & mask) ? orvalue : 0);
>    }
>    return rev;
>}
>
>This has some sort of bit flipper:
>http://www.mactech.com/articles/mactech/Vol.14/14.12/Dec98ProgChallenge/
>
>C++ template idea:
>http://coppercode.com/resources_bit_basics.htm

More of the same. The last article implements something similar to what I did in
assembly. I am beginning to think that nobody has anything better than the ((x
<< n) & mask) | ((x >> n) & mask) method -- which is pretty good by itself.
Perhaps some of the shifts can be eliminated.

-Matt



This page took 0 seconds to execute

Last modified: Thu, 15 Apr 21 08:11:13 -0700

Current Computer Chess Club Forums at Talkchess. This site by Sean Mintz.