UPGRADE YOUR BROWSER

We have detected your current browser version is not the latest one. Xilinx.com uses the latest web technologies to bring you the best online experience possible. Please upgrade to a Xilinx.com supported browser:Chrome, Firefox, Internet Explorer 11, Safari. Thank you!

cancel
Showing results for
Search instead for
Did you mean: kp1998_
Observer
286 Views
Registered: ‎06-11-2019

## Conversion of floating-point to fixed-point in verilog

Jump to solution

Hello

I want to convert 0.707 into fixed point value for my verilog code.Can u please explain how is conversion of floating-point value to fixed-point value done in verilog .

Thanks

Regards

Neha

1 Solution

Accepted Solutions u4223374
Scholar
268 Views
Registered: ‎04-26-2015

## Re: Conversion of floating-point to fixed-point in verilog

Jump to solution

If you just want to code it in as a constant, then there's no need to do the conversion in the Verilog code - you can do the conversion externally and just code the result.

The process is very simple: just multiply your input number by 2^F where F is the number of fraction bits in your fixed-point value. For example, if you've got a 16-bit fixed-point value with 10 fraction bits, then:

0.707 * 1024 = 723.968, rounded to 724

724 in binary = 0000001011010100

Putting the binary point in there at the appropriate point (ie ten digits from the right, because there are ten fraction bits) we have 000000.1011010100. Converting back to decimal gives you 0.707031, which is as close as you can get with that fraction length.

3 Replies u4223374
Scholar
269 Views
Registered: ‎04-26-2015

## Re: Conversion of floating-point to fixed-point in verilog

Jump to solution

If you just want to code it in as a constant, then there's no need to do the conversion in the Verilog code - you can do the conversion externally and just code the result.

The process is very simple: just multiply your input number by 2^F where F is the number of fraction bits in your fixed-point value. For example, if you've got a 16-bit fixed-point value with 10 fraction bits, then:

0.707 * 1024 = 723.968, rounded to 724

724 in binary = 0000001011010100

Putting the binary point in there at the appropriate point (ie ten digits from the right, because there are ten fraction bits) we have 000000.1011010100. Converting back to decimal gives you 0.707031, which is as close as you can get with that fraction length. kp1998_
Observer
256 Views
Registered: ‎06-11-2019

## Re: Conversion of floating-point to fixed-point in verilog

Jump to solution
Thank you so much
Highlighted markcurry
Scholar
244 Views
Registered: ‎09-16-2009

## Re: Conversion of floating-point to fixed-point in verilog

Jump to solution

Adding on to @u4223374 response, I'd just like to add that I find it much easier to model, and think of the fixed point number as a scale on integer values rather than "Putting the binary point in there at the appropriate point".

i.e. how I model, and think of your example, you have a 16 bit value (signed or unsigned) representing "764".  This can be interpreted as a real by multiplying by the scale: 764 * 2**(-10) = 0.707031, as was shown.  But the scaling value (2**-(10)) is usually set aside, in your notebook mostly, and not really needed all that much in your processing.  When doing further processing, one must correctly handle the scales of all terms of the operation.

We learn to align the "decimal" points in grade school to do maths.  But I find it easier in digital electronics to think in terms of an integer value, and a scale.  Your mileage may vary of course, but I find things MUCH easier with this way of modelling, and thinking.

Regards,

Mark