简体   繁体   中英

Double decimal number convert to HEX string

I want to convert a decimal number(17592186044416) to hex string in MFC. AndI have tried to use

code 1:
double ftw = 0;
CString str;
str.Format(_T("%X"), ftw); //this will always be 0 in HEX

code 2:
char t1[100];
_itoa_s(ftw, t1, 16);// this will give me 80000000 in HEX

It seems like the str.Format(_T("%X"), ftw); and _itoa_s(ftw, t1, 16); function has the limit. Is there any other command that I can use to get the 17592186044416 to hex string? Thank you.

You can cast it to a 64-bit integer and then format using the I64 qualifier in your format string:

double ftw = 17592186044416.0;

CString str;
str.Format(_T("%I64X"), (__int64)ftw);

For the example above, str will have the string "100000000000"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM