mr_stevie
asked on
Converting a Hex CString to Decimal CString
Hello.
I know there are many resources available for this question but they all don't seem to work for me for some reason.
I am trying to convert a CString representing a hex number into a CString containing a decimal number.
For example:
CString hexstring = 07BE;
CString decimalstring;
I want to convert 07BE to 1982.
If anyone can help, will be greatly appreciated!
Thank you in advance.
I know there are many resources available for this question but they all don't seem to work for me for some reason.
I am trying to convert a CString representing a hex number into a CString containing a decimal number.
For example:
CString hexstring = 07BE;
CString decimalstring;
I want to convert 07BE to 1982.
If anyone can help, will be greatly appreciated!
Thank you in advance.
ASKER
Unfortunately, i get the follow errors:
For strtol():
Error 1 error C2664: 'strtol' : cannot convert parameter 1 from 'CString' to 'const char *'
Error 2 error C2664: 'void ATL::CStringT<BaseType,Str ingTraits> ::Format(c onst wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
For_tcstol():
Error 3 error C2664: 'wcstol' : cannot convert parameter 2 from 'char **__w64 ' to 'wchar_t **'
Error 4 error C2664: 'void ATL::CStringT<BaseType,Str ingTraits> ::Format(c onst wchar_t *,...)' : cannot convert parameter 1 from 'const char [3]' to 'const wchar_t *'
For strtol():
Error 1 error C2664: 'strtol' : cannot convert parameter 1 from 'CString' to 'const char *'
Error 2 error C2664: 'void ATL::CStringT<BaseType,Str
For_tcstol():
Error 3 error C2664: 'wcstol' : cannot convert parameter 2 from 'char **__w64 ' to 'wchar_t **'
Error 4 error C2664: 'void ATL::CStringT<BaseType,Str
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Unfortunately, that still gives me problems.
However, I think I've managed to figure it out.
For some reason, char* isn't working properly and I'm using a wchar_t*.
Also, "%d" needs to be _T("%d") to convert to UNICODE.
Otherwise, the following code seems works fine!
Thank you very much!
However, I think I've managed to figure it out.
For some reason, char* isn't working properly and I'm using a wchar_t*.
Also, "%d" needs to be _T("%d") to convert to UNICODE.
Otherwise, the following code seems works fine!
Thank you very much!
wchar_t *p;
sDec.Format( _T("%d") , _tcstol( sHex, &p, 16 ) );
Open in new window