Monday, 17 November 2014

vhdl - Conversion from fixed point to IEEE 754



I am trying to design a simple processor (in VHDL) that takes in its input a real number coded in the fixed point representation in 2's complement (10 bits for the integer part, and 6 for the fractional part), and outputs its IEEE 754 single-precision format equivalent:


enter image description here


I have been searching for a while now, and still couldn't find any resources on this type of conversion, at least some flow chart from which I could start.



Answer



Basically, you do four things:



  • convert from 2’s complement to signed magnitude, save the sign

  • count leading zeroes (find first ‘one’)


  • add a bias to that to make the exponent

  • shift the integer to normalize it as the mantissa.


About four lines of code that synthesizes to some logic, an adder, and a shift mux.


EDIT: As Tim said, before you do all that you also need to convert the 2’s complement integer to signed magnitude. So one more line.


No comments:

Post a Comment

arduino - Can I use TI's cc2541 BLE as micro controller to perform operations/ processing instead of ATmega328P AU to save cost?

I am using arduino pro mini (which contains Atmega328p AU ) along with cc2541(HM-10) to process and transfer data over BLE to smartphone. I...