I would like to create a VHDL coding whereby a certain two's complement value 'n' will be multiplied by 7/8 Is it possible to create such an arithmetic? In short, what i want is n X 7/8 = m if i multiply a two's complement value by 7/8, wouldn't that create an integer? basically why i need this 7/8 value is because when a machine is 7/8 distance from the intended destination, the machine will slow down. Hence the 7/8.
What i thought of was to multiply the two's complement with booth's algorithm and then use the subtraction method to divide the value.any better suggestions? Anyone can help me out with the coding? thanks.
>> when a machine is 7/8 distance from the intended destination, the machine will slow down. Hence the 7/8.
So it doesn't have to be 100% accurate ? If so, you can divide by 8 first (shift right by 3) and then multiply by 7. You'd lose some of the lower-order bits, but maybe that's no problem, as you'll only compare the value anyway ... you be the judge ;)
The alternative is to convert to a floating point value, in which case you can be more precise, but of course you're working with floating point operations which are usually more expensive.
If the value will never be larger than INT_MAX / 7, then you can of course multiply first, and then divide, keeping the exact value (rounded to an integer).
For n < 8 (n/8) * 7 would give you inaccurate results!!
What I and ozo tried to demonstrate here was low cost and low effort method for doing it. If value of n is a concern then use more storage!! If you are using a soewhat recent processor which has an FPU then even floating point operations wont be expensive.