gelbeiche
2006-03-10 10:31:11 UTC
Hi,
I want to create a hex output of int values and used the following
function:
inline std::string stringify(int x)
{
std::ostringstream o;
o << std::hex << std::setw(2) << std::setfill('0') << x;
return o.str();
}
For negative ints I get strings like
ffffffca or ffffffef
for positive ints
3c,64 ...
How can I accomplish *always* to get 2 byte strings(in the example above
"ca" instead of "ffffffca").
(
Of course I could do something like
if ( s.length() == 8 )
s.erase(s.begin(), s.begin() + 6);
but it is not nice
)
Thomas
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
I want to create a hex output of int values and used the following
function:
inline std::string stringify(int x)
{
std::ostringstream o;
o << std::hex << std::setw(2) << std::setfill('0') << x;
return o.str();
}
For negative ints I get strings like
ffffffca or ffffffef
for positive ints
3c,64 ...
How can I accomplish *always* to get 2 byte strings(in the example above
"ca" instead of "ffffffca").
(
Of course I could do something like
if ( s.length() == 8 )
s.erase(s.begin(), s.begin() + 6);
but it is not nice
)
Thomas
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]