Computer Chess Club Archives


Search

Terms

Messages

Subject: Re: The idee looks nice. What do you think about n xor (n-2)?

Author: Robert Hyatt

Date: 19:37:16 07/01/01

Go up one level in this thread


On July 01, 2001 at 10:40:42, stefan wrote:

>But why not n xor (n-1)?
>
>Thanks for your comment.


N & N-1 is a well-known trick to clear the rightmost bit of a number.  IE
if you take the value 7, then 7 & 6 is 6 (rightmost bit now off).  Repeating,
you have 6 left.  6 & 5 is 4.  and finally, 4 & 3 is zero and they are all
now off, being cleared one at a time.

XOR N and N-1 doesn't seem to do anything useful in the context of bitmaps.

IE if you start off with 7, 7^6 is 1 (the right bit.)  If you repeat this
with 6, 6^5 is 3, which doesn't seem important.

XOR N and N-2 is just another boolean operation.

7^5 is 2 (next to rightmost bit set).

15 ^ 13 is 2 (next to rightmost bit set)

If you need to get to the second bit, then this seems to do the trick.
I don't need that in any of my code however, so I don't see why any of it
is relevant here.

The first thing to do when playing with bitmaps is to figure out what features
you need.  Then find cute ways to discover that feature.  You should not start
out discovering all the crypto tricks with bit twiddling and then try to figure
out how they might be used in a bitmap engine..



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.