Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Decimal to Hex with CString 1

Status
Not open for further replies.

HyperEngineer

Programmer
May 8, 2002
190
US
How do I convert a decimal number (integer or long) to a hex string. The ones I've seen in this an the other C++ forum use the hex method with cout. I want to put the result in a CString.

Code:
  CString sHexString;
  long lDecValue;
  
  lDecValue = 3101334
  sHexString = hex(lDecValue);

When compiling I get an error that says it can't convert form long to std::ios_base &.

Any help would be appreciated.

HyperEngineer
If it ain't broke, it probably needs improvement.
 
I never use CString, but you can do it with stringstream:
Code:
#include <sstream>
#include <iostream>
#include <iomanip>

using namespace std;

int main( void )
{
    int i = 0x3F8D;
    stringstream s;

    s << hex << i;
    cout << "Hex = " << s.str() << endl;
    return 0;
}
 
Code:
sHexString.Format ("%08X", lDecimalValue);
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top