#include <systemc.h>
#include <iostream>
#include <iomanip>
int sc_main(int argc, char* argv[])
{
sc_dt::sc_uint <12> my_uint = 0;
std::cerr << std::hex << my_uint << std::endl;
}
g++ test.cpp -lsystemc && ./a.out
打印此:
SystemC 2.3.1-Accellera --- Jul 24 2017 21:50:41
Copyright (c) 1996-2014 by all Contributors,
ALL RIGHTS RESERVED
0000
是表示四個零(16位),而不是三個(12位),因爲你可能希望它會,因爲這是如何12- SystemC中實現了一個整數。它不會被std::setw
縮短,因爲它將字符的最小編號設置爲。如果有更多的字符,那麼所有的字符都會被寫入。另外值得一提的是,你的例子中的std::dec
什麼都不做,因爲之後沒有打印數字。
http://www.cplusplus.com/reference/ios/ios_base/width/
http://www.cplusplus.com/reference/iomanip/setw/
這將打印僅低12位最後3個字符:
#include <systemc.h>
#include <iostream>
#include <iomanip>
const unsigned CHARS = 3;
const unsigned MASK = (1u << CHARS * 4) -1; // Same as 0xFFF
int sc_main(int argc, char* argv[])
{
sc_dt::sc_uint <12> my_uint = 0xABC;
std::cerr << std::hex
<< std::setw (CHARS) << std::setfill ('0')
<< (my_uint & MASK) << std::endl;
}
這取決於什麼功能'運營商<<(STD :: ostream的和,sc_dt :: sc_uint '定義要做。 –