@rShetty : In function add: c=x&y; // c has those bits set which have a carry x=x^y; //after this instruction x would contain the result if we had neglected the carry. //Now which positions have a carry can be checked by c by shifting it to left by 1 bit. Thats what we are doing in the next instruction y=c<<1; //This loop is followed untill we have no carry, i.e. untill y is 0. //In the next cycle of the loop, y contains the carry bits, which are added to x.
In the function mul : In each iteration, we are picking least significant bit of multiplier and if it is 1, we are adding the multiplier to the result.And we are shifting the multiplicand to the left by 1 bit. I think u must try running a test case on paper... It would be clear... -- You received this message because you are subscribed to the Google Groups "Algorithm Geeks" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/algogeeks?hl=en.
