In the SV with the $bitstorealshort () function can easily convert hexadecimal, binary number into a single-precision floating point, the following is the source code, in the MODELSIM10.1C test pass, the file needs to be saved as. sv File
Module h2f;
Integer FID_RD;
Integer FID_WR;
// Integer FID_MIF;
bit [11:0] variable=0;
bit [31:0] value;
int h_array[0:1023];
Shortreal fr;
Initial BEGIN:FILE_RD
FID_RD = $fopen ("Rd_h.txt", "R");
if (Fid_rd = = 0)
Disable FILE_RD;
while (! $feof (FID_RD)) begin
if (! $feof (FID_RD) = =-1)
Break
$FSCANF (FID_RD, "%h", value);
H_array[variable] = value;
variable = variable + 1 ' B1;
End
$fclose (FID_RD);
FID_WR = $fopen ("H2f.txt", "w");
foreach (H_array[i]) begin
FR = $bitstoshortreal (h_array[i]);
$display ("%d%f", I,FR);
$fdisplay (FID_WR, "%f", FR);
End
$fclose (FID_WR);
End
Endmodule
$bitstorealshort () function in SV