ciccio.greco88 Posted December 13, 2012 Report Share Posted December 13, 2012 Hi guys, i've a variable sc_uint<32> pippo to which i want to assign a value in an hexadecimal form but this value has a decimal form, how can i do it? Help me! Thanks! Greetings. Francesco. Quote Link to comment Share on other sites More sharing options...
Philipp A Hartmann Posted December 13, 2012 Report Share Posted December 13, 2012 How do you see, whether a value has a decimal or hexadecimal representation? Most probably, it is stored in some form of binary in the memory. ;-) But you can directly assign both hex literals (C++ feature) and hex strings (SystemC datatypes feature) to sc_uint variables: #include <systemc.h> int sc_main(int,char*[]) { sc_uint<32> pippo; // ... pippo = 0x2A; // assign from hex literal pippo = "0x0A2"; // assign from hex string std::cout << pippo // decimal value by default << "=" << pippo.to_string(SC_HEX) // SystemC hex representation << " (0x" << std::hex << pippo <<")" // C++ hex representation (with manual '0x' prefix) << std::endl; return 0; } Gotcha: In SystemC, hex strings are signed literals by default. When dealing with unsigned variables (sc_uint, et.al), you should make sure that the hex string contains a leading 0 to avoid unexpected sign extension, when converting from the hex string. Greetings from Oldenburg, Philipp maehne 1 Quote Link to comment Share on other sites More sharing options...
Abdallah Posted March 3, 2022 Report Share Posted March 3, 2022 Hello All , I have a similar question but for a bit vector : sc_signal<sc_bv<40>> maddress ; If I want to drive the addess value in hexadecimal to the input of the DUT based on previous feedback I should be able to assign it as below ? maddress = "0x8979E54200"; Also here a leading 0 is not required (as in the sc_uint case ?) due to it is a sc_bv type ? Many thanks Regards Abdallah Quote Link to comment Share on other sites More sharing options...
David Black Posted March 4, 2022 Report Share Posted March 4, 2022 Have you considered reading the specification (IEEE-1666-2011) - see section 7.3 String Literals on page 199? Have you tried: `maddress->write(sc_bv<40>("0x8979E54200"));` and had problems? Are you properly trained in C++? Note: Using `operator->` is preferred over `operator.` Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.