Author: stefan
Date: 03:49:49 07/03/01
Go up one level in this thread
On July 02, 2001 at 15:51:56, Landon Rabern wrote: >On July 01, 2001 at 22:37:16, Robert Hyatt wrote: > >>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. > >It just set all the bits up to the first 1 bit and clears all higher bits. >Whether or not tis is useful is another question. I think this should be good for sliding pieces in set all bits up to the first blocking piece?
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.