ashfaq2419
Programmer
dear friends,
i am implementing a structure, in which i have to do some multiplications and additions/subtractions. for multiplication i am using shift-add technique e.g. if my input number is 'a' and it has to be multiplied by 51, i simply do it like (a<<5)+(a<<4)+(a<<1)+a. but the problem is with the sign. e.g. a=-32 and i am using 10 bits to represent it.
now the question is that i know that the multiplicand is always positive i.e. 51, but input number can either be positive or negative. how can i manage this thing so that the sign of the output is always correct. please guide me in detail and i have tried a lot to understand the phenomenon but to no avail.
regards
i am implementing a structure, in which i have to do some multiplications and additions/subtractions. for multiplication i am using shift-add technique e.g. if my input number is 'a' and it has to be multiplied by 51, i simply do it like (a<<5)+(a<<4)+(a<<1)+a. but the problem is with the sign. e.g. a=-32 and i am using 10 bits to represent it.
now the question is that i know that the multiplicand is always positive i.e. 51, but input number can either be positive or negative. how can i manage this thing so that the sign of the output is always correct. please guide me in detail and i have tried a lot to understand the phenomenon but to no avail.
regards