hello all
many thanks for your replies. naturally, i'm a bit disappointed with
the reviews :) can you point me at good internet literature about the
alternatives? however, for completeness, i also put the following
subtraction under the original BSD license:
the problem with the subtraction is that detecting the carry isn't that
easy. boolean XOR catches both 1->0 and 0->1, though only the first case
is to be considered. for a luck, filtering the first case out can be
done with a combination of XOR and AND. this is just how the other
algorithm worked except that using the XOR for both the basic addition
and the first step of the calculation of the carry needs some change in
the order of re-using the values. also, the bitshift must be done before
the carry is used in the next XOR because the shifted value is also the
correct input for the next AND. confused? just look at the following
code in c:
int main ()
{
// boolean subtraction with bit shifting
unsigned int x = 23; // the first value
unsigned int y = 15; // the second value, which is also the
// carry bitfield
while (y != 0)
{
x = x ^ y; // first calculating the addition or, from then,
// the merging with the current carry bitfield
y = y & x; // before the result becomes the second input of
// the calculation of the next carry
y = y << 1; // shifting the carry to merge it with x
} // already beginning from above again
if (x == 8)
printf("test passed!\n");
return 0;
}
in the end, this algorithm is even easier than the other. one can skip
the third variable for the carry (at least in code this makes a
difference.)
regards,
dennis heuer
lehrte/hannover
germany
_______________________________________________
Open-graphics mailing list
[email protected]
http://lists.duskglow.com/mailman/listinfo/open-graphics
List service provided by Duskglow Consulting, LLC (www.duskglow.com)