Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Bitboards question

Author: Robert Hyatt

Date: 17:03:13 11/29/99

Go up one level in this thread


On November 29, 1999 at 17:36:27, Nicolas Carrasco wrote:

>Hi,
>
>I am studying BITBOARDS programs and I had found this piece of code:
>//////////////////////////////////////////////////////
>int msb[65536];   // this array will contain the number of the first 1 bit
                   // for _any_ 16 bit value.
>
>BITBOARD mask;
>
>msb[0]=16;        // normal values should be 0-15.  16 -> no 1 bit set
>for (c=1;c<65536;c++)
>{
>   mask=32768;    // this is a 1 bit in position -1 (the real bit positions
                   // are bit 0 thru bit 15.)  We are going to shift this bit
                   // right one bit at a time and use it to check to see if thet
                   // bit is set in the word we are testing.  by counting the
                   // number of times this bit gets shifted, we know how many
                   // zero bits we have skipped over.
>   for (k=0;k<16;k++)  // this tests bits 0 thru 15, one after the other
>   {
>      if (mask & c)  //  if the bit is set, we store the bit number and exit
>      {
>         msb[c] = 15 - k;
>         break;
>      }
>      mask = mask>>1; //  otherwise we shift it right one bit and test again.
>   }
>}
>//////////////////////////////////////////////////////
>
>That that code do?
>How it is used at Bitboards?
>
>Thanks
>
>http://www.puntadeleste.to/uruchess/


my first thought is that you really don't want to deal with bitmaps if you
can't interpret the code above.  But see the comments I inserted to understand
what it does...



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.