Electronic – How to convert a floating point number to integer, using VHDL

floating pointvhdl

I want to convert a floating point number to a integer number. Basically I have a floating point number between 1 and 0, with three decimal places, and I want to pass it to a integer number as if multiplied by 1000. I suspect there should be a more optimal way to do it than using the arithmetic multiply operation x1000.
I'm looking for a piece of code preferably.

Best Answer

Well, since you don't want to use a power of two for your multiplication, it's going to be a PITA. I'll show you what would be more ideal after answering your question. I'm not going to provide any code - just technique.

The Hard Way (x 1000)

  1. Multiply the mantissa of your 0-1 number with the mantissa of 1000 (Multiply by a Constant)
  2. Add the exponent of your 0-1 number with the exponent of 1000 (Add a constant)
  3. Normalize the mantissa/exponent to the form 1.XXX*2^Y (variable shift, add)
  4. Adjust the mantissa/exponent so that the exponent is 10 (Can be combined with previous step) (shift, add)
  5. Take 10 bits of data to the left of the decimal point as your integer

The Easy Way (x 1024)

  1. Normalize the mantissa for an exponent of 2^10 (variable shift)
  2. Take the 10 most-significant-bits as your integer value