Hi,
I want to convert fractional part - kfrac in the below task to binary. I tried to use the $realtobits system task, but this will compromise on the precision as I will need only 5 bits starting from LSB out of 64 bits. So, what’s the best way to convert it to binary in SV?
task compute_k();
target_res = $urandom_range(200,45);
k = (rterm_target - inductor_res) * 8/(target_res - inductor_res);
kint = $rtoi(k);
kfrac = k - kint;
$display("Kint :: %d, Kfrac :: %f, K :: %f", kint, kfrac, k);
endtask
Thanks
In reply to nimitz_class:
It would help to show the declarations of all variables and include a set of example values you are expecting.
In reply to dave_59:
In reply to nimitz_class:
It would help to show the declarations of all variables and include a set of example values you are expecting.
module computeK();
localparam real rterm_target = 45;
localparam real inductor_res = 7;
localparam real static_legs = 5;
localparam real target_res = 200;
real k, kfrac;
int kint;
task compute_k();
k = (rterm_target - inductor_res) * 8/(target_res - inductor_res);
kint = $rtoi(k);
kfrac = k - kint;
$display("Kint :: %d, Kfrac :: %f, K :: %f", kint, kfrac, k);
endtask
initial begin
compute_k();
end
endmodule
Sim result : Kint :: 1, Kfrac :: 0.575130, K :: 1.575130
I want to convert 0.575 to binary