Hi all..

I would like to convert a hex to CString format..
I had try like below I shown, but failed to convert into CString format that I wish to..
Here is the example I tried..

CString sz;
unsigned short test = 0xB0FF0000;
sz.Format("%X", test);

then I got sz = "0x0000"..and this value is not the value that I given to convert..

I'm using Microsoft Visual C++ 6.0..with SP4 and SP5..
can anyone tell me how to convert a Hex to CString..??

Please advice..
Thank you..
shizu..

In decimal, the hex value you're assigning is: [B]2969501696[/B] , and unless you're using a very powerful computer this won't fit in an unsigned short.
First try it with a simple value, for example 0xF, this should convert correctly.

Hi tux4life..

Thanks for reply..
I had try another code like below..

CString sz;
unsigned int test = 0xB0FF0000;
sz.Format("%x", test);

Then I got the result sz = "b0ff0000"..
but the sz value that I got is different than yours one..
means the code is wrong..??

Can you please guide me, where are my mistake is..??

Thank you..
shizu..

Hi tux4life..

Thanks for reply..
I had try another code like below..

CString sz;
unsigned int test = 0xB0FF0000;
sz.Format("%x", test);

Then I got the result sz = "b0ff0000"..
but the sz value that I got is different than yours one..
means the code is wrong..??

Can you please guide me, where are my mistake is..??

Thank you..
shizu..

No, now there's nothing wrong with your code.
Your code is working fine now.
The value I said was the equivalent decimal value for the hexadecimal value you used in your code: 2969501696 and 0xB0FF0000 are both the same, except that the first one is in decimal, and the second one is in hexadecimal.

This question has already been answered. Start a new discussion instead.