- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi all;
I want to convert 0.483 to ufixed type. Manually, I get 0000.0111 (3 downto -4) when I calculate by hand. But, this value is not same with the value in modelsim which is 0000.1000. I write like this; ip1<=to_ufixed(0.483,n1); What the correct value of 0.483 in ufixed? Do I calculate in wrong way?..needs help, thanksLink Copied
10 Replies
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Its 0000.1000 if you round to nearest.
the to_ufixed function does have extra options with regards to rounding and saturation. You'll have to read the function definitions in the fixed_pkg source code or user guide to set them.- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
0.483 * 2^4 = 7.728, which gets rounded up to 8, which is 1000 in binary. To me it seems Modelsim is right.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry, what actually the formula to convert to ufixed? thanks for reply
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Y x 2^f, where f is the number of fractional bits.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
I try 1 example (0.25) for my better understand;
0.25x2^2 = 0.5 which get rounds 1, which is 1 in binary. Do I right? thanks for reply- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
0.25*2^2 = 1
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
--- Quote Start --- I try 1 example (0.25) for my better understand; 0.25x2^2 = 0.5 which get rounds 1, which is 1 in binary. Do I right? thanks for reply --- Quote End --- No, 0.25 x 2^2 = 1 Answer is 0.01
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Sorry for the miss typing..and I think I misunderstanding the concept.
I try another example (9.75): 9.75x2^2=39 which is 100111 in binary. The answer is 1001.11 Do I right? thanks for reply- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Yes this is right
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Okay I undersatand now, many thanks Tricky and Daixiwen!
Reply
Topic Options
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page