Using C++'s stream-based IO (as shown in the other answer) is probably the best approach, however, if you really want to use fprintf()
, then you have the option of using the sc_dt::sc_bigint<W>::to_string()
method. For example:
#include <systemc>
#include <cstdio>
using namespace std;
int sc_main(int argc, char **argv) {
FILE *fp = fopen("sc_bigint.txt", "w");
sc_dt::sc_bigint<88> x("0x7fffffffffffffffffffff"); // (2 ** 87) - 1
fprintf(fp, "x = %s (decimal)\n", x.to_string().c_str());
fprintf(fp, "x = %s (hexadecimal)\n", x.to_string(sc_dt::SC_HEX).c_str());
return EXIT_SUCCESS;
}
The above SystemC program writes the following to a file sc_bigint.txt
:
x = 154742504910672534362390527 (decimal)
x = 0x7fffffffffffffffffffff (hexadecimal)