Author: Uri Blass
Date: 20:25:00 07/06/03
In movei I have a number between 0 and 255 and I want to do some functions for
every 1 that it has in its binary representation(number of functions to
implement is the same as the number of 1's in the number and there is a
different function based on the value of the 1)
I do not like to call functions because functions use local varaibles and
generating a copy of the local varaibles only to forget them may take computer
time and I also do not use the functions more than once.
I thought to use switch(see the code later in this post) but the problem is that
switch continue to do everything without break and I want to have switch that
does not continue to do everything but does not quit and simply forget about the
fact that I called switch.
Here is the type of the code that I plan to have now.
I do not like all the if (number&2) or if (number&4) and the question is if I
can do it faster.
i=smallestpower[number];
switch(i)
{
case 0:do list of commands
if (number==1) break
else
{
number-=1;
i=smallestpower[number];
}
case 1:if (number&2)
{
do list of commands
if (number==2) break;
else
{
number-=2;
i=smallestpower[number];
}
}
case 2:if (number&4)
{
do list of commands
if (number==4) break;
else
{
number-=4;
i=smallestpower[number];
}
}
case 3:if (number&8)
...
...
case 6:if (number&64)
...
case 7://if you got there you know that number is 128 because you did not get
out by break so you do not need to check it
Uri
This page took 0.02 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.