**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!

Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Community Forums
- :
- Forums
- :
- Design Tools
- :
- Design Entry
- :
- Re: Conversion of floating-point to fixed-point in...

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

kp1998_

Observer

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-26-2019 03:21 AM

277 Views

Registered:
06-11-2019

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

Highlighted

u4223374

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-26-2019 05:19 AM

259 Views

Registered:
04-26-2015

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

Highlighted

u4223374

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-26-2019 05:19 AM

260 Views

Registered:
04-26-2015

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-26-2019 05:31 AM

247 Views

Registered:
06-11-2019

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

Thank you so much

markcurry

Scholar

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

06-26-2019 01:01 PM

235 Views

Registered:
09-16-2009

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

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