将十六进制转换为双倍到十六进制
Convert Hex to Double to Hex?
在我的项目中,我有一个带有十六进制值的QString(大端序)
QString hex_in("413DF3EBA463B0");
如何将hex_in转换为四舍五入的双精度?IEEE 754 (https://en.wikipedia.org/wiki/Double_precision_floating-point_format)
34.5
用户将编辑双精度,然后我的程序需要将其转换回十六进制。
感谢您抽出宝贵时间:)
实际上
只有一种方法可以做到这一点,那就是将字符串转换为整数,将其放入设置整数成员并读出double
成员的union
中。
对于字符串转换,您可以使用例如这些函数之一。
示例代码:
double hexstr2double(const std::string& hexstr)
{
union
{
long long i;
double d;
} value;
value.i = std::stoll(hexstr, nullptr, 16);
return value.d;
}
// ...
std::cout << "413DF3EBA463B0 = " << hexstr2double("413DF3EBA463B0") << 'n';
上面代码的输出将是
413DF3EBA463B0 = 1.91824e-307
double HexToDouble(AnsiString str)
{
double hx ;
int nn,r;
char * ch = str.c_str();
char * p,pp;
for (int i = 1; i <= str.Length(); i++)
{
r = str.Length() - i;
pp = ch[r];
nn = strtoul(&pp, &p, 16 );
hx = hx + nn * pow(16 , i-1);
}
return hx;
}
我的大十六进制数字函数
结果
72850ccbb88c6226afed9d8d971c8938 --> 1.5222282653101E+38
000015d85a903c72b6bebdd18fb26811 --> 4.4307191280143E+32
相关文章:
- 将字符指针十六进制转换为字符串并保存在文本文件C++中
- 将十六进制转换为 DEC
- 将字符指针中的十六进制转换为十进制
- 使用 std::hex 将十六进制转换为十进制
- 将40个字节长的数据框从十六进制转换为二进制,然后转换为十进制
- 如何将十六进制转换为十进制
- 在C++中将十六进制转换为uint8_t
- 从十六进制转换为LPCVoid,切断了一半地址
- 将十六进制转换为可打印的字符串/字符
- 将 QString 十六进制转换为 ASCII 值
- 我如何在 C++ 中将变量从十六进制转换为 dec
- 混淆在C++中将十六进制转换为二进制
- C++中的十进制到十六进制转换代码
- 如何在C++中将十六进制转换为IEEE 754 32位浮点
- 十进制到十六进制转换错误
- 十进制到十六进制转换c++内置函数
- 如何将十六进制转换为字符串?C++
- 将 3d 数组元素从十六进制转换为二进制以获得 bmp
- C++:将十六进制转换为十进制
- 将十六进制转换为签名的十二月