Search code examples
verilogfixed-point

how to out fixed point value in verilog?


I'm trying to out the fixed point value in verilog. Generally, I use like this method (I'don't know what it was called) for example,

output = 0.248*5
output = ((0.248 << 8) * 5 ) >> 8;

But in his case the output has only integer.

I want to get fixed point fraction part.

How to handle to out the fixed point value in verilog?


Solution

  • To calculate and display with 8 fractional bits:

    integer out;
    
    initial begin
      out = ((0.248 * 2**8) * 5 );
      $display("%f", $itor(out)*(2.0**-8.0));
    end