2

I am trying to measure how much have accuracy when I convert to binary fixed point representation way. first I tried use this 0.9375. And I got the binary 0.1111. second I tried used this 0.9377 and I also got the binary 0.1111

There is nothing different between them.

Also how can I solve this problem? Is there any other way? To make converting ?

For your understand, I let me know some more example, For example, If I want to convert 3.575 to binary then 3.575 be 11.1001. but If I back to again to decimal then 3.5625. It so quite different on original value.

JamJI
  • 77
  • 1
  • 11

1 Answers1

2

From a similar question we have:

Base 2: Twos complement 4 integer, 4 bit fractional

-2^3  2^2  2^1  2^0  .  2^-1    2^-2    2^-3    2^-4
  -8    4    2    1  .   0.5    0.25   0.125  0.0625

With only 4 fractional bits the represented number only has an accuracy of 0.0625

3.575 could be 11.1001 = 2+ 1+ 0.5 + 0.0625 => 3.5625 to low
      or       11.1010 = 2+ 1+ 0.5 + 0.125  => 3.625  to high

This should indicate that 4 bits is just not enough to represent "3.575" exactly.

To figure out how many bit you would need multiply by a power of 2 until you get an integer: For "3.575" it is rather a lot (50 fractional bits).

3.575 * 2^2   = 14.3 (not integer)
3.575 * 2^20  = 3748659.2
3.575 * 2^30  = 3838627020.8
3.575 * 2^40  = 3930754069299.2 (not integer)
3.575 * 2^50  = 4025092166962381.0 (INTEGER) we need 50 bits!

3.575 => 11.10010011001100110011001100110011001100110011001101

Multiplying by a power of two shift the word to the left (<<) When there is no fractional bits left it means the number is fully represented, then number of shifts is the number of fractional bits required.

For fixed point you are better off thinking about the level of precision your application requires.

Community
  • 1
  • 1
Morgan
  • 18,407
  • 6
  • 54
  • 78
  • 1
    Thank you very much again, Mogan. – JamJI Jan 28 '15 at 00:34
  • 1
    Sir, this is other question from your above answer. For 3.75, it is a lot needed fractional bit almost 50.However, i want to know about how efficient this is compared to contents i will introduce next. I use this way, first 3.75<<1024 then do something arithmetic operation then back to again like this, x >>1024. Of course, this way have a little error(precision) what the last number. But, as the aspect of area and speed, this way is rather than the first way. But I want to your opinion – JamJI Jan 28 '15 at 01:11
  • 1
    @JamJI. Verilog does not have a fixed point type, so you must shift to add fractional bits. BUT the number will be stored as an integer. If you right shift (`>>1024`) you will be throwing the fractional bits away. The precision you need really does depend on the application. If you can get the performance you require with fewer fractional bits then it will synthesise easier. – Morgan Jan 28 '15 at 08:19