I am trying to demonstrate to my class mates the run time difference in using
bit-wise and logical operators. I chose to do this by writing a simple (I thought) program
that reads 2 ints from the console, and multiplies them two separate times, one using
the logical multiply (a * b) and one using a shift-add algorithm. However, I am stumped in finding a way to use this method in all cases. Lets say that below is my program:
int x, y, logicalOp, bitwiseOp;
logicalOp= x*y;
bitwiseOp= num << mult#
obviously, logicalOp and bitwiseOp should yield the same result.
The green text is what is giving me trouble. Can anybody offer some advice for a shift-add formula that works for small ints (<100)?