超出long本身长度的数据,无法直接用long来表示,如果强制把double转换为long,丢失数据就大了,
所以我们采用ULONGLONG或__int64来表示,下面给出两个例子,17位的double转换为16进制字符串,
仅供参考:
(1)
double dd=82753683737018368.0000;
ULONGLONG ull = (ULONGLONG&)dd;
ull &= 0x1fffffffffffff;
CString source;
source.Format(_T("%I64x"), ull);
AfxMessageBox(source);
这个例子可以参考我发的帖子,牛人!在此表示感谢!
http://topic.csdn.net/u/20090402/13/a229dd9c-6e33-484c-a3bf-fda7b67eee33.html
验证转换的结果是否正确:http://www.knowsky.com/tools/ToolJinzhi.asp
(2)
double d=81627781917573120.0000;
__int64 nNum = (__int64)d;
CString strHex = "";
while (nNum/16 > 0)
{
__int64 nMod = nNum % 16;
switch(nMod)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: str.Format("%d",nMod); break;
case 10: str = "A"; break;
case 11: str = "B"; break;
case 12: str = "C"; break;
case 13: str = "D"; break;
case 14: str = "E"; break;
case 15: str = "F"; break;
}
nNum = nNum/16;
strHex = str + strHex;
}
if(nNum>0)
{
switch(nNum)
{
case 0:
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9: str.Format("%d",nNum); break;
case 10: str = "A"; break;
case 11: str = "B"; break;
case 12: str = "C"; break;
case 13: str = "D"; break;
case 14: str = "E"; break;
case 15: str = "F"; break;
}
}
strHex = str + strHex;
AfxMessageBox(strHex);
验证转换的结果是否正确:http://www.knowsky.com/tools/ToolJinzhi.asp
仅供参考,欢迎大家提意见!