Booth algorithm gives a procedure for multiplying binary integers in signed 2’s complement representation in efficient way, i.e., less number of additions/subtractions required. It operates on the fact that strings of 0’s in the multiplier require no addition but just shifting and a string of 1.
I have included the program in which I am having a logical problem. The program is based on booth's algorithm and I have put a snippet of it. In this 'working' snippet decimal number is accepted from the user converted to decimal form with the help of array (a[0]=1 LSB) and lastly the 2s complement is calculated of array b[]. Now, when I run the program:
Output
Here in the output I expect the 6th line as 0101 but get 1101. Why are the values of array b[] changing? The value of array b[] at line 5 is correct so why does it change? According to the code the value shouldnt be changing right? I am stuck.. Please help!! Any suggestion will be appreciated!!
2 Answers
b, q and comb are array of 3 elements so b[3] is an array overflow (whose value is unknown). In fact comb being allocated right after b it is likely that b[3] equals comb[0].
You are doing an overflow . Do it like this. Simple .