Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Need help with nearest bit algorithm

Author: Jaime Benito de Valle Ruiz

Date: 11:52:41 01/10/04

Go up one level in this thread


On January 10, 2004 at 14:28:58, Chris Hull wrote:

>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

What is the role of "Position" in this function? In your example you've just
worked out the absolute highest and lowest bits of "X", regardless of the value
of "Position".
Can you give me an example where the value of "Position" makes a difference
compared to FindHighestBit(int X) and FindLowestBit(int X)?



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.