Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Mirroring a 32bit bitboard

Author: Dann Corbit

Date: 14:48:46 04/09/02

Go up one level in this thread


On April 09, 2002 at 17:32:15, Alvaro Jose Povoa Cardoso wrote:

>Does anyone kow how to do a fast 32bit bitboard mirroring?
>bit 0  ->  bit 31
>bit 1  ->  bit 30
>bit 2  ->  bit 29
>...etc
>
>I would like to do it fast.
>
>Best regards,
>Alvaro Cardoso

From:
http://www.cs.ucsd.edu/~kgatlin/papers.html

Here is some code by Kang Su Gatlin:

int logn(int n)
{
        int i = 0;
        n = n -1;
        while(n > 0)
        {
                i++;
                n = n >> 1;
        }
        return(i);
}


int bitrev(int x, int lgn)
{
        int i, t, value;

        value = 0;


        for(i = lgn-1; i >= 0; i--)
        {
                t = 1 & x;
                value = (value | (t << i));
                x = x >> 1;
        }

        return(value);
}


The logn function can be done a tiny bit faster.



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.