Computer Chess Club Archives


Search

Terms

Messages

Subject: Need help with nearest bit algorithm

Author: Chris Hull

Date: 11:28:58 01/10/04


I am trying to find a fast algorithm that will return the closest bit to a given
bit. I searched google but found nothing.

Here is an example problem stated as concisely as I can.

Given:

    111111
    5432109876543210    // bit positions

X = 0101000100000101    // binary
Postion = 8

/** Here is the problem we are trying to solve
    Find nearest bit higher than bit number 8 and
    find nearest bit lower than bit number 8 **/

X' = 0101000*00000101

so if

Y = int FindNearestHigherBit( int X, int Position );
Z = int FindNearestLowerBit( int X, int Position );

then

Y = 0001000000000000
Z = 0000000000000100

So I am looking for the function/algorithm for FindNearestHigherBit and
FindNearestLowerBit. I would like one that runs fast (ie one clock cycle)
and not a loop that looks at every bit.

Ok, all you who were CS major in college help me out. Thanks in advance.


Chris



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.