python - 将 float 重铸为 gdb 中的 ieee754 表示形式

标签 python linux shell gdb

嗨,我正在玩以下内容,我想在 Linux shell 中在 IEEE754 表示形式和十进制 float 之间进行转换。我发现的唯一方法是:

gdb --batch -ex "print/x (float *) ( (float) 1234.567 )"

gdb --batch -ex "print/f (float *) 0x449A5225"

但它不适用于 double 和 long double(“无效转换”),而且 gdb 也会截断大于 32 位的值,因此 double 和 long double 。

有gdb专家帮忙吗?

最佳答案

我用 Python 找到了自己的解决方案:

# python -c 'import struct; print "%#x" % struct.unpack("I", struct.pack("f", 1234.567))'
0x449a5225

# python -c 'import struct; print "%#x" % struct.unpack("Q", struct.pack("d", 1234.567))'
0x40934a449ba5e354

# python -c 'import struct; print "%f" % struct.unpack("d", struct.pack("Q", 0x4094b2449ba5e354))'
1324.567000

# python -c 'import struct; print "%f" % struct.unpack("f", struct.pack("I", 0x449a5225 ))'
1234.566895

关于python - 将 float 重铸为 gdb 中的 ieee754 表示形式,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24453649/

相关文章:

bash - 为什么交互式 shell 的子 shell 作为交互式 shell 运行?

python - cv2.imshow() 函数显示正确的图像,但在使用 cv2.imwrite() 函数保存它时,它保存所有黑色像素图像?

regex - 用小写字母替换下划线

python - dconf 中 a(ss) 类型的含义是什么? gi.repository.Gio.Settings 获取/设置此类字段的正确方法是什么?

C++ getline(string) 与多线程有关的段错误

linux - Makfile 选项的含义

python - 在 Sympy 中使用抽象数学运算符/对象

python - PyQt Paint 自定义日期格式

python - 在djangorest框架中使用postman上传图像时出错

python - Windows 和 LInux 上的 USB 设备/PyUSB 表现不同