Guilherme Garcia
Guilherme Garcia

Reputation: 161

How do I convert a DWORD to HEX

I'm currently using C Builder:

DWORD finalAddress = 0xFFFFFFFF;
TListItem *ListIt;
ListIt->Caption = finalAddress;

This will output: 4294967295 (which is 0xFFFFFFFF in DEC)

I want it to show 0xFFFFFFFF.

How do I do that?

Upvotes: 3

Views: 8287

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727047

Assuming that you have access to C++ standard library, try this:

#include <sstream>
#include <iostream>
#include <string>

std::ostringstream ss;
ss << std::hex << finalAddress;

AnsiString ansiHex = AnsiString (ss.str().c_str());
ListIt->Caption = ansiHex;

This last assignment may not work - I do not have access to Embarcadero's headers, so I have no idea what's the type of ListIt->Caption. There may be need to perform additional conversion.

Upvotes: 2

Related Questions