Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: Quick bit extraction question

Author: Rémi Coulom

Date: 05:29:43 07/20/04

Go up one level in this thread


On July 20, 2004 at 08:19:25, Andrew Wagner wrote:

>Being the great genius that I am, it dawned on me the other day that creating a
>custom class to handle things like moves, which can be stored easily in
>integers, was not terribly efficient. So, let's say, for example, I'm storing
>the 'to' square for a move in the right-most (least-significant) 7 bits of an
>integer, the 'from' square in the next 7 least significant bits, and possibly
>other information in other (more significant) bits. What's the most efficient
>way to knock off extra, more significant bits? I want to do something like this:
>to = move MOD 128;
>from = (move>>7) MOD 128;
>
>...but not sure if that's most efficient. Thanks! Andrew

Are you programming in BASIC or C++ ? The modulo operator in C++ is "%". A more
natural way to write your assignments would be to replace "% 128" by "& 127". A
good optimizing compiler would do it by itself and compile the same code, I'd
guess. In case the compiler does not perform the optimisation, the AND operator
is a lot faster than MODULO. I am not sure it is the most efficient solution,
but it is what I do in The Crazy Bishop.

Rémi



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.