MFC应用程序,添加两个编辑框,并给各编辑框添加一个变量(CString m_float、CString m_hex)。
void CMFCFloatToHexDlg::OnBnClickedBtnF2h()
{
UpdateData(TRUE);
float f = _tstof(m_float);
long hex = *(long*)&f;
m_hex.Format(_T("%X"), hex);
UpdateData(FALSE);
}
void CMFCFloatToHexDlg::OnBnClickedBtnH2f()
{
//十六进制形式的CString,转换为long,再转换为CString
UpdateData(TRUE);
//char* stops, s[3];
//char d[4];
//for (int i = 3, j = 0; i >= 0; i--, j++)
//{
// s[0] = m_hex.GetAt(i * 2);
// s[1] = m_hex.GetAt(i * 2 + 1);
// s[2] = 0x0;
// d[j] = (UCHAR)strtoul(s, &stops, 16);
//}
//float f = *((float*)d);
long hex = _tcstoul(m_hex, nullptr, 16);
float f = *((float*)&hex);
m_float.Format(_T("%0.6f"), f);
UpdateData(FALSE);
}
MFC CString和十六进制互转
https://blog.csdn.net/zb774095236/article/details/88795565
浮点型与16进制数据的相互转换(C语言代码)
https://blog.csdn.net/qq_43537721/article/details/107757766
strtoul, _strtoul_l, wcstoul, _wcstoul_l
https://learn.microsoft.com/zh-cn/cpp/c-runtime-library/reference/strtoul-strtoul-l-wcstoul-wcstoul-l?view=msvc-170
atoi, _atoi_l, _wtoi, _wtoi_l
https://learn.microsoft.com/zh-cn/cpp/c-runtime-library/reference/atoi-atoi-l-wtoi-wtoi-l?view=msvc-170
将字符串转换为 unsigned __int64 值
如何以快速安全的方式将十六进制字符串转换为无符号64位(uint64_t)整数?
https://www.orcode.com/question/1013075_k8b894.html
十六进制CString转__int64
https://blog.csdn.net/denglxk/article/details/7900784
c语言16进制转uint64,CString::Format格式化64位16进制格式&&CString格式化64位整数注意事项…
https://blog.csdn.net/weixin_28811007/article/details/117143451