Computer Chess Club Archives


Search

Terms

Messages

Subject: Speaking of low bit, here is an idea from Lawrence Kirby on c.l.c

Author: Dann Corbit

Date: 21:12:43 01/21/02


#include <stdio.h>

static const unsigned int S_lowbit_lookup[] = {
     0,  1,  2,  6,  3, 11,  7, 16,  4, 14, 12, 21,  8, 23, 17, 26,
    31,  5, 10, 15, 13, 20, 22, 25, 30,  9, 19, 24, 29, 18, 28, 27
};

#define NUMBITS 32
#define LOWBIT(x) S_lowbit_lookup[(((x) & -(x))*0x04653adf >> 27) & 0x1f]

int main(void)
{
    int bit;

    printf("%08lx:%2u\n", 0UL, LOWBIT(0UL));

    for (bit = 0; bit < NUMBITS; bit++) {
        unsigned long value1 = 1UL << bit;
        unsigned long value2 = value1 * 15;

        printf("%08lx:%2u   %08lx:%2u\n", value1, LOWBIT(value1),
                                          value2, LOWBIT(value2));
    }

    return 0;
}



This page took 0.01 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.