Author: Albert Bertilsson
Date: 12:40:49 04/07/03
Hi I would be very happy for any help with two functions:
First out is the PopCount for 16 bit integers, I modified a 32bit popcount and
got this:
unsigned int Ones16(register unsigned short int x)
{
x -= ((x >> 1) & 0x5555);
x = (((x >> 2) & 0x3333) + (x & 0x3333));
x = (((x >> 4) + x) & 0x0f0f);
x += (x >> 8);
return(x & 0x003f);
}
Any improvements?
Next is a bit more odd and I've never seen a special funktion for this problem.
What I have is an short int with one bit set for a piece. What I want to do is
to get the index of any of one of the bits set.
So if I have 0x06, the function should return either 1 or 2 (starting from 0),
doesn't matter which. The order is unimportant since I want to look at all
anyway, so when I've got the first index I intend to do "x &= x - 1", and
continue using the "GetOneIndex" function.
The reason that I don't want to go through the usual and obvious shifting
operation is that I expect very few bits to be set like 2 or 3 ones.
Any suggestions are welcome!
/Regards Albert
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.