Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
661 views
in Technique[技术] by (71.8m points)

verilog - How much have xxx precision binary fixed point representation?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...