Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

[SOLVED] $realtobits function in verilog

Status
Not open for further replies.

raghavkmr

Junior Member level 2
Joined
Nov 26, 2013
Messages
23
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Activity points
194
Code:
module real2bits();

real n;
reg  [63:1]b;

initial begin

n = 15.0 ;
$display("n---->%f",n);
$display("b---->%b",b);
#1

b = $realtobits(n);
$display("b---->%b",b);
#10
$finish;

end

endmodule



output is --->

n---->15.000000
b---->xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
b---->100000000101110000000000000000000000000000000000000000000000000



which is wrong for n=15 ,b should be 1111

why this is happening
 

If you want b to have the value 'b1111, then just do b = n;

$realtobits returns the simulator's internal representation of a real/floating number. It's only purpose in Verilog was that was the only way to pass a real value through module port. You would then use the $bitstoreal function to convert the value back to real without any loss of precision. There is no longer any need for these functions in SystemVerilog because you can pass real types value through ports.
 
Thanks dave ,my problem is solved
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top